0
votes

I'm working on android's canvas view. I just want to know if this condition is valid semantically.

if(bitmap.getPixel(x,y) == Color.WHITE)

I logged the value of Color.WHITE by:

int white = Color.WHITE; and this gave me the value of -1 and value of black color was -1633377 something.

I found the way of getting the value of any pixel in bitmap by getPixel() method and it returns an ARGB value. I've tried various ways to do this but none succeeded.

Can you guys help me with this?

Thanks.

1
Your if clause should work to check, if pixel's color is white. See: developer.android.com/reference/android/graphics/Color.htmlRhinoDevel

1 Answers

3
votes

Please check here

The color's Alpha, Red, Green and Blue components are each stored on one byte (so values in [0-255]) and those 4 bytes are packed in a java "int" which is usually 4 bytes.

You get negative values because you use a signed int, in C++ you would use a unsigned int, but those are not available in Java, more info here

So to answer your question, yes your condition is valid semantically, -1 is the (signed) int value for 0xFFFFFFFF, and Black is not zero probably because this is opaque black, so with alpha=255 => 0xFF000000