Custom Search

Saturday 24 April 2010

Processing-07. Data Type : Variables-02

Image

  Processing can load .gif, .jpg, .tga, and .png images. Images can be displayed in 2d or 3d space. In order for an image to be used, a variable for an image must be defined by PImage() function and the image must be loaded with loadImage() function.

1. Load and Display an image
  The same way that intergers are stored in variables of the int data type and true/false values are stored in the boolean data type, images are stored in variables of the PImage data type.
e.g.) PImage img;     // define a variable 'img' as an image variable.

  In order to load an image into the defined variable, loadImage() function is used to load an image into the sketch. You need to be sure to include the file format extension as a part of the name and to put the entire name in quotes. Be careful to use the correct capitalization and do not use spaces in image names, which can cause error.
e.g.) img=loadImage("apple.jpg");      // load apple.jpg into an image variable 'img'.