We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Storing images into arrays
Page Index Toggle Pages: 1
Storing images into arrays (Read 320 times)
Storing images into arrays
Jun 7th, 2009, 9:18am
 
I want to load an image directly into an array of "color" datatype.

The way I am doing this implies on displaying the image in the screen and then loading the pixels array, then copying it to another array, then clearing the screen with background(), because I don't want the image to really be seen.

The bad thing is that it clears the entire screen, and for my project this really screws everything up. And yet there must be a easier way to do it directly. I searched the reference but couldn't find anything that loads an image to an array, instead of a PImage object.

thanks
Re: Storing images into arrays
Reply #1 - Jun 7th, 2009, 12:19pm
 
You can load the image in a PImage, then use its pixels[] array.
Re: Storing images into arrays
Reply #2 - Jun 7th, 2009, 1:59pm
 
Yup, you don't have to display an image to use its pixels[] array.

Code:

for (int i = 0; i < number_of_logos; i++) {
// fill logo_array;
String nr = str(i);

logo_array[i] = loadImage("logo_"+nr+".gif");
logo_array[i].loadPixels();

// analyzing pixels
for (int pix = 0; pix < logo_array[i].pixels.length; pix++) {

int r = int(red(logo_array[i].pixels[pix]));
int g = int(green(logo_array[i].pixels[pix]));
int b = int(blue(logo_array[i].pixels[pix]));
int a = int(alpha(logo_array[i].pixels[pix]));
}
}

Re: Storing images into arrays
Reply #3 - Jun 7th, 2009, 7:40pm
 
thanks buddies, it worked perfectly.
Page Index Toggle Pages: 1