This reference is for Processing 2.0+. If you have a previous version, use the reference included with your software. If you see any errors or have suggestions, please let us know. If you prefer a more technical reference, visit the Processing Javadoc.

Class | PImage
Name | ### pixels[]
Examples |
    PImage tower;

    void setup() {
      size(100, 100);
      tower = loadImage("tower.jpg");
      int dimension = tower.width * tower.height;
      tower.loadPixels();
      for (int i = 0; i < dimension; i += 2) {
        tower.pixels[i] = color(0, 0, 0);
      }
      tower.updatePixels();
    }

    void draw() {
      image(tower, 0, 0);
    }
Description | Array containing the values for all the pixels in the image. These values are of the color datatype. This array is the size of the image, meaning if the image is 100 x 100 pixels, there will be 10000 values and if the window is 200 x 300 pixels, there will be 60000 values. The index value defines the position of a value within the array. For example, the statement color b = img.pixels[230] will set the variable b equal to the value at that location in the array. Before accessing this array, the data must loaded with the loadPixels() method. After the array data has been modified, the updatePixels() method must be run to update the changes. Without loadPixels(), running the code may (or will in future releases) result in a NullPointerException.
Syntax |
    pimg.pixels[]
Parameters |
pimg | PImage: any object of type PImage

Updated on May 19, 2014 05:30:03pm PDT