2

I need to get the color of a pixel in order to compare it with a color from my color.xml file, but all values are negative and this comparison will always return a false result. How to get the proper color value? This color may be transparent. I've read this but I need an answer, not a link to theory.

bmp.getPixel(n.x, n.y) is returning zero when I'm expecting to return a propper value for color #00FFFFFF

Thanks

Community
  • 1
  • 1
Buda Gavril
  • 21,409
  • 40
  • 127
  • 196
  • Haven't done this in android but isn't something like Color c = bmp.getPixel(..., ...); available? => c.R, c.G, c.B. would be the rgb values. –  Mar 10 '12 at 13:50

1 Answers1

6

You could do something like this:

int pixel = Color.RED; //bmp.getPixel(n.x, n.y);
int a = Color.alpha(pixel);
int r = Color.red(pixel);
int g = Color.green(pixel);
int b = Color.blue(pixel);

String color = String.format("#%02X%02X%02X%02X", a, r, g, b); //#FFFF0000 for RED color

but instead of Color.RED you can put your bmp.getPixel(...) method.

Hope that helps

Best Regards

bart
  • 186
  • 2
  • 4