User Tools

Site Tools


Pixel Map Issues

The pixel[] array can be confusing:

This was a window originally sized at 500×500. The image is 500×333. In draw(), a call is made to size(400,333), and the length of pixels[] is output immediately after.

First of all, the calls to size() after the initial call do not change the size of the window itself. Instead, they change the area available for output. This means that if you removed the call to size(400,333), the rest of the picture would be shown (it would fill the blue area). That call shrinks the area available for output, and the picture is truncated to the size of the red area.

The pixels[] array is everything displayed in the window- including grey areas. So, calls to size(), loadImage(), image(), etc. do not change the size of pixels[]. Throughout the program that created this picture, the length of pixels[] was 251500 (500×500+ 1500 mystery pixels).

The PImage.pixels[] array (separate from the other pixels[] array, which is global) always represents the picture, even when part of it is made non-visible. This is quite useful… I wish I had figured that out earlier.

When using the PImage.pixels[] array:

  • Don't have to use loadPixels()
  • Use get() and set() to change color values
  • Have to use PImage.updatePixels()
  • Have to call image() after updating pixels.

When using the global pixels[] array:

  • Call loadPixels()
  • Change the array- direct access
  • Call updatePixels()
  • No need to call image() again- pixels[] is re-read during every call to draw()
pixel_map_issues.txt · Last modified: 2007/08/30 13:53 (external edit)