[英]How can I extract ARGB from a Color and convert them to byte components?
I'm working in Java/Android and I want to take the 0xFFFFFFFF
int color and break it into 4 bytes for red, green, blue and alpha. 我正在Java / Android中工作,我想采用
0xFFFFFFFF
int颜色并将其分成4个字节,分别表示红色,绿色,蓝色和Alpha。 I know Color
has methods for extracting specific color values, but it gives them as an int
. 我知道
Color
有提取特定颜色值的方法,但它将它们作为int
给出。 I've gone through the SDK and found that the Color.red(color)
method is the same as saying (color >> 16) & 0xFF
, honestly I have no idea what this means but I think I can use this in some way. 我遍历了SDK,发现
Color.red(color)
方法与说(color >> 16) & 0xFF
相同,说实话我不知道这意味着什么,但是我认为我可以以某种方式使用它。
I've tried doing 我试着做
byte red = (byte)Color.red(color);
but this doesn't seem to work. 但这似乎不起作用。 The whole point is so I can feed in the values into OpenGL with the method
重点是,我可以使用方法将值输入OpenGL
glColorPointer(4, GL_UNSIGNED_BYTE, 4, myColors);
myColors being a byte[]. myColors是一个字节[]。
Any help/tips/points would be greatly appreciated. 任何帮助/提示/要点将不胜感激。
If Color has methods for extracting specific color values then extract Red as int and make it Hex then Green then Blue. 如果“颜色”具有提取特定颜色值的方法,则将“红色”提取为int值,然后将其提取为“十六进制”,然后设为“绿色”,然后设为蓝色。 You might also want to extract alpha.
您可能还希望提取alpha。 with
Integer.toHexString(int)
you can print the Hex value of an int. 使用
Integer.toHexString(int)
,可以打印Integer.toHexString(int)
的十六进制值。 (color >> 16) & 0xFF
positions the Red color (by bitshifting and adding) to the first 2 out of 6 hexdigits of a non alpha Color. (color >> 16) & 0xFF
将红色(通过位移位和相加)定位到非alpha颜色的6个十六进制数字中的前2个。 non alpha Color RBG consists of 3 bytes of information. 非alpha颜色RBG由3个字节的信息组成。 Every byte is one Color with the order R(Red) B(Blue) G(Green) .
每个字节都是一种颜色,其顺序为R(红色)B(蓝色)G(绿色)。 0xFF is one byte, if set to Red means that the Color has full red etc etc
0xFF是一个字节,如果设置为红色则表示颜色具有全红色等
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.