从负 int 值中获取 RGB 值
我必须从 RGB 转换为 HSB,以便对图像执行直方图均衡化。我已将其转换回 RGB,并且得到一个负值,例如 -158435。谁能帮助我了解如何将其转换为颜色,以便我可以将其设置为我的像素?谢谢
i had to convert from rgb to hsb so as to perform histogram equalization on an image. I have converted it back into rgb and i am getting a negative value like -158435. Can anyone please help me understand how to convert this into a colour so i can set it to my pixel? Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需利用位移位即可。有用。
然后使用这个方法
Color.RGBtoHSB(int r, int g, int b, float[] hsbvals);
就像this:要将其转换回来,只需使用其他方法(已编辑,你是对的):
Simply make use of the bit-shifting. It works.
Then use this method
Color.RGBtoHSB(int r, int g, int b, float[] hsbvals);
like this:To convert it back, simply use the other method (edited, you were right):
出现负值是因为您将颜色存储为 ARGB(Alpha Red Green Blue)。
Alpha 通道通常是 100% 不透明,即 255 = 0xFF。
因此,当颜色转换为32位int时,它显示为负值。
示例:不透明黑色 = ARGB(255, 0, 0, 0) = 0xFF000000 = -16777216
The negative value appears because you are storing colors as ARGB (Alpha Red Green Blue).
The alpha channel is then often just 100% opaque, which is 255 = 0xFF.
Therefore, when the color is converted to an 32 bit int, it appears negative.
Example: Opaque Black = ARGB(255, 0, 0, 0) = 0xFF000000 = -16777216