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 & HelpPrograms › getting a color out of a PImage
Page Index Toggle Pages: 1
getting a color out of a PImage (Read 659 times)
getting a color out of a PImage
Nov 15th, 2008, 1:51pm
 
i'd like to get all colors out of a PImage into a 2 dimensional color array.
how can i get a color out of an image (using specified pixel coordinates)?
Re: getting a color out of a PImage
Reply #1 - Nov 15th, 2008, 7:58pm
 
get() function. But actually, for faster run, read the page and look at loadPixels().
Re: getting a color out of a PImage
Reply #2 - Nov 17th, 2008, 8:34pm
 
thanks, i am using .get() right now. but why do i get int values instead of color objects?
i want to iterate over an image pixel by pixel, get every color of the current pixel and then calculate the average color of the given image.

but when i calculate the average color of for example this mostly green image: http://www.photoschau.de/images/20060526231036_green_accumulation.jpg i get the int value -538, which is some kind of white-ish. what can i do?
Re: getting a color out of a PImage
Reply #3 - Nov 17th, 2008, 9:46pm
 
You need to use red(col); (or green() or blue() ) on the int returned.

Within processing colours are actually stored as ints, 'color' is just a synonym for int really.

Each int is bade up of 32 bits, 8 each for opacity (alpha) red, green and blue, stuck together to make it easy to pass around internally.
Re: getting a color out of a PImage
Reply #4 - Nov 18th, 2008, 1:04am
 
that was the problem! thanks!
Page Index Toggle Pages: 1