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 › Copying single pixel colors from image to an array
Page Index Toggle Pages: 1
Copying single pixel colors from image to an array (Read 306 times)
Copying single pixel colors from image to an array
Feb 24th, 2009, 3:14pm
 
Hi,
I need to be able to copy pixel colors from a small image (32,23) into an array of the same dimensions. I've never done this before, but i'm able to load images and draw them to the screen and store numbers in my array pretty easily.

I'm guessing something like:
Code:

for (int i=0; i < col; i++) {
for (int j=0; j < row; j++) {
grid[i][j]=MYIMAGE(i,j);
}
}


The final complication is that my array is storing color as a single float, 0 - 1.0
Can I grab my image's color as a single gray scale and divide by 255?
Re: Copying single pixel colors from image to an a
Reply #1 - Feb 24th, 2009, 3:36pm
 
Have you looked into pixels[] reference?

If this image is displayed, it is the array you need just ready for you to use...

look for "pixels[]" in your processing reference.

But if the image is not displayed? Can one access it's pixel[] array?
half an answer half a question...
Re: Copying single pixel colors from image to an a
Reply #2 - Feb 24th, 2009, 5:08pm
 
Hahah, I noticed this feature too. Can I 'display' an image off screen and copy the pixels down?

Not sure I even fully understand it's use, sort of a pixel color clipboard?
Re: Copying single pixel colors from image to an a
Reply #3 - Feb 24th, 2009, 5:45pm
 
actually it is an array containing all pixels color information of the given screen. Its one dimension array so  the pixel at pixels[width+1] is actually the first pixel of the second line of the display.  If you say "color c= pixels[10]" you are seting "c" to the color of the 10th pixel in first line of the display. In the other hand "pixels[10] = color (255)" is making the 10th pixel of the first line of the display a "white dot".
You need to call "loadPixels()" before messing with pixels[] and "updatePixels()" to display the changes you've done.
try and see...
Page Index Toggle Pages: 1