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 › extract rgb values
Page Index Toggle Pages: 1
extract rgb values (Read 891 times)
extract rgb values
Mar 9th, 2007, 11:05pm
 
image.get returns a 32 bit number (AAAAAAAARRRRRRRRGGGGGGGGBBBBBBBB).

We are trying to extract rgb values for the 32 bit binary string. We need to break the string into 4 parts (alpha, r, g, b values) and then convert them back into separate integers that can be used in other programs.

We were thinking of creating 4 new strings and appending successive bits to each 8 bit string based on location in the original 32 bit string and then converting the  8 bit strings to ints.

The problem we are facing is getting specific bits from the original string and placing into another string. We have not been able to add a character to a string  using charAt() and we are looking for advice on what to try next.

any help to find the right direction would be greatly appreciated.

thanks

Greg
Re: extract rgb values
Reply #1 - Mar 10th, 2007, 12:27am
 
http://processing.org/reference/green_.html

http://processing.org/reference/red_.html

http://processing.org/reference/blue_.html

http://processing.org/reference/alpha_.html

F
Re: extract rgb values
Reply #2 - Mar 10th, 2007, 1:28am
 
the red/green/blue functions are okay, but if you want speed, you can do it manually:

Code:
color c=image.get(...);

int a=(c>>24)&0xFF;
int r=(c>>16)&0xFF;
int g=(c>>8 )&0xFF;
int b=c&0xFF;

Re: extract rgb values
Reply #3 - Mar 14th, 2007, 7:19pm
 
Thanks for the input, both methods work well. I am grateful.

greg
Page Index Toggle Pages: 1