在Android中获取位图的RGB值
我在 Android 中获取位图的 RGB 值时遇到一些问题... 这就是我正在做的:
int[] temp = new int[width*height];
bit.getPixels(temp, 0, width, 0, 0, width, height);
但是,颜色似乎与典型的 RGB 值不匹配。例如,白色像素将显示为 -1,而它的 RGB 值为 16777215。(我从以下网站获取该值:http://www.shodor.org/stella2java/rgbint.html)
还有大量似乎不合适的负值正常的 RGB 值。我的问题是是否有一种方法可以转换为典型的 RGB 值,而不是 getPixels() 方法返回的 Android 颜色整数。感谢您的帮助,如果您有任何疑问,请告诉我。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
也许你可以尝试
getPixel
首先,看起来会更容易。否则,您能否在问题中提供更多代码(如何声明位图,从何处获取 -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...)
根据 文档,-1 是白色,实际上, 16777215 是十六进制的 0xffffff,相当于 -1。
Color
的所有数字都是负数,因为十六进制值中有前导 f。十六进制值中的前导 ff 指定 alpha 值或不透明度。如果颜色完全不透明,则数字将以 ff 开头,如果颜色完全透明,则数字将以 00 开头。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.将值存储在无符号整数中。
Store the value in an unsigned integer.