tags:

views:

311

answers:

2

I have the integer pixel i got from get.rgb(x,y), but i dont have any clue about how to convert it to RGBA. For example, -16726016 should be Color(0,200,0,255). Any tips?

+5  A: 

If I'm guessing right, what you get back is an unsigned integer of the form 0xAARRGGBB, so

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

would extract the color components. However, a quick look at the docs says that you can just do

Color c = new Color(argb);

or

Color c = new Color(argb, true);

if you want the alpha component in the Color as well.

AKX
Sweet potatoes!
Gabriel A. Zorrilla
+2  A: 

Hi,

    Color c = new Color(-16726016);
    System.out.println(c.getRed());
    System.out.println(c.getGreen());
    System.out.println(c.getBlue());
    System.out.println(c.getAlpha());

prints out: 0 200 0 255

Is that what you mean?

amir75