首页 > 文档 > requestImage()请求图像(单线程)
2017
08-08

requestImage()请求图像(单线程)

Name

requestImage()请求图像(单线程)

   

Examples

PImage bigImage;

 

void setup() {

bigImage = requestImage(“something.jpg”);

}

 

void draw() {

if (bigImage.width == 0) {

// Image is not yet loaded

} else if (bigImage.width == -1) {

// This means an error occurred during image loading

} else {

// Image is ready to go, draw it

image(bigImage, 0, 0);

}

}

Description

This function loads images on a separate thread so that your sketch doesn’t freeze while images load during setup(). While the image is loading, its width and height will be 0. If an error occurs while loading the image, its width and height will be set to -1. You’ll know when the image has loaded properly because its width and height will be greater than 0. Asynchronous image loading (particularly when downloading from a server) can dramatically improve performance.

The extension parameter is used to determine the image type in cases where the image filename does not end with a proper extension. Specify the extension as the second parameter to requestImage().

此函数在单独的线程上加载图像, 这样在安装过程中加载图像时, 草绘不会冻结。当图像加载时, 其宽度和高度将为0。如果在加载图像时发生错误, 则其宽度和高度将设置为-1。您将知道图像何时加载正确, 因为它的宽度和高度将大于0。异步映像加载 (特别是从服务器下载时) 可以显著提高性能。

 

扩展参数用于在图像文件名未以适当的扩展名结束的情况下确定图像类型。将扩展名指定为 requestImage () 的第二个参数。

Syntax

requestImage(filename)

requestImage(filename, extension)

 

Parameters

filename

String: name of the file to load, can be .gif, .jpg, .tga, or a handful of other image types depending on your platform

要加载的文件的名称, 可以是. gif,. jpg,. tga, 或少数其他图像类型, 取决于您的平台

extension

String: the type of image to load, for example “png”, “gif”, “jpg”

要加载的图像的类型, 例如 “png”“gif”“jpg”

Returns

PImage

Related

PImage
loadImage()



最后编辑:
作者:卡萨布兰卡
卡萨布兰卡
这个作者貌似有点懒,什么都没有留下。

留下一个回复

你的email不会被公开。