android Bitmap getPixel

孤街浪徒 提交于 2019-12-04 01:58:16

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/9646899/android-bitmap-getpixel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!