Get RGBValues of Bitmap in Android

江枫思渺然 提交于 2019-12-13 02:20:28

问题


I'm having some issues getting the RGB values of a bitmap in Android... This is what I'm doing:

int[] temp = new int[width*height];
bit.getPixels(temp, 0, width, 0, 0, width, height);

However, the colors don't seem to match the typical RGB values. For example, a white pixel will show up as -1, whereas the RGB value for it is 16777215. (I'm getting that value from this website: http://www.shodor.org/stella2java/rgbint.html)

There's also a ton of negative values which don't seem to fit normal RGB values. My question is if there is a way to convert to the typical RGB values as opposed to the Android Color integers which the getPixels() method returns. Thanks for any help and let me know if you have any questions.


回答1:


Maybe you can try getPixel first, seems like it would be easier.

Otherwise, can you give more code in your question (how do you declare the bitmap, where you get that -1 value from...etc...)




回答2:


According to the documentation, -1 is White, and really, 16777215 is 0xffffff in hex, which is equivalent to -1.

All of the numbers for Color's are negative, because there is the leading f in the hexadecimal value. There is the leading ff in the hexadecimal value to specify the alpha value, or the opacity. If a color is completely opaque, then the number will lead with ff, if the color is completely transparent, the number will lead with 00.




回答3:


Store the value in an unsigned integer.



来源:https://stackoverflow.com/questions/6501527/get-rgbvalues-of-bitmap-in-android

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