PImage pixel array is an array of ints


im loading a jpg image and displaying the underlying pixel array. The picture has the same amount of pixels as the canvas, which is 438 x 1200. However when printing out the contents of the canvas’ pixel variable and the image’s pixel variable, we can see that these arrays are not of the same length. More specifically, the image’s pixel variable has a length of 1051200, which is 4 times the length of the canvas’ pixel array. I dont think this is supposed to happen?


Hi mchangxe,

The size of your image is not the size of your canvas so the size of the pixels array can be different. Check the dimension of “pos2.jpg” in your file explorer and that should match the 1051200 that you found.

Then it is normal that you get ints as a result because of the ways color are coded inside Processing: https://processing.org/reference/color_datatype.html

This way of encoding means that all the information of a color is contain within only one variable. So when you get pixels[10] you get the entire color information of the 10th pixel.

So you can’t do that: color(img1.pixels[0], img1.pixels[1], img1.pixels[2], img1.pixels[3])
But you can do that: background(img1.pixels[3])