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 › converting color value to rgb
Page Index Toggle Pages: 1
converting color value to rgb (Read 382 times)
converting color value to rgb
Dec 31st, 2008, 11:22pm
 
hello , im using "get" to store the color of all the pixels of  an image into an array , how can i convert the values im getting  to rgb? how can i convert each value i get from "get" to 3 values corresponding to red, green and blue?

thanks


mateo
Re: converting color value to rgb
Reply #1 - Dec 31st, 2008, 11:53pm
 
There's the built in ways:

Code:
color c=get(200,200);
println("Red:"+red(c)+" Green:"+green(c)+" Blue:"+blue(c));


This takes into account the colour mode etc and gives you results relative to whatever settings you have. But it's not the fastest way of getting the values if you're checking a lot of pixels.

The quick way, gives values from 0..255 regardless of the colorMode.

Code:
color c=get(200,200);
int r=(c>>16)&255;
int g=(c>>8)&255;
ing b=c&255;
Page Index Toggle Pages: 1