Name

loadPixels()

Class

PImage

Description

Loads the pixel data of the current display window into the pixels[] array. This function must always be called before reading from or writing to pixels[]. Subsequent changes to the display window will not be reflected in pixels until loadPixels() is called again.

Examples

  • PImage myImage;
    int halfImage;
    
    void setup() {
      size(400, 400);
      halfImage = width * height/2;
      myImage = loadImage("wood.jpg");
      myImage.loadPixels();
      for (int i = 0; i < halfImage; i++) {
        myImage.pixels[i+halfImage] = myImage.pixels[i];
      }
      myImage.updatePixels();
    }
    
    void draw() {
      image(myImage, 0, 0);
    }
    Image output for example 1

Syntax

  • pimg.loadPixels()

Parameters

  • pimg(PImage) any object of type PImage

Return

  • void