a port of the Processing Visualization Language
Name

loadImage()

Examples
example pic

    // @pjs preload must be used to preload the image 

    /* @pjs preload="laDefense.jpg"; */

    PImage b;

    b = loadImage("laDefense.jpg");

    image(b, 0, 0);

example pic

// @pjs preload must be used to preload the image

/* @pjs preload="laDefense.jpg"; */

PImage b;

void setup() {

  b = loadImage("laDefense.jpg");

  noLoop();

}



void draw() {

  image(b, 0, 0);

}
PImage online;



void setup() {

  String url = "http://mt0.google.com/mt?n=404&v=w2.61&x=9913&y=12119&zoom=2";

  online = loadImage(url, "png");

  noLoop();

}



void draw() {

  image(b, 0, 0);

}
Description Loads an image into a variable of type PImage. Four types of images ( .gif, .jpg, .tga, .png) images may be loaded. To load correctly, images must be located in the data directory of the current sketch, the images must be preloaded using @pjs preload specifying the path to the image. In most cases, load all images in setup() to preload them at the start of the program. Loading images inside draw() will reduce the speed of a program. You can also load images from a data URI, such as "data:image/jpg;base64,{base 64 encoded data block}" which does not require any preloading.

The filename parameter can also be a URL to a file found online. For security reasons, a Processing sketch found online can only download files from the same server from which it came.

The extension of the filename 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 loadImage(), as shown in the third example on this page.

If an image is not loaded successfully, the null value is returned and an error message will be printed to the console. The error message does not halt the program, however the null value may cause a NullPointerException if your code does not check whether the value returned from loadImage() is null.

NOTE: Some browers will not allow you to load images from file:// URIs. It is recommended that you use a webserver for your development and testing to avoid any problems with file:// URIs.
Syntax
loadImage(filename)
Parameters
filename string: name of file to load or data URI/td>
Usage Web & Application
Related PImage
image()
imageMode()
background()

This reference is licensed under the CC BY-NC-SA 2.0 license:

Creative Commons License
Fork me on GitHub