开发者

How can I extract ARGB from a Color and convert them to byte components?

开发者 https://www.devze.com 2023-04-01 02:12 出处:网络
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. I know Color has methods for extracting specific color values, but it

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. I know Color has methods for extracting specific color values, but it gives them as an 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.

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

glColorPointer(4, GL_UNSIGNED_BYTE, 4, myColors);

myColors being a byte[].

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. You might also want to extract alpha. with Integer.toHexString(int) you can print the Hex value of an 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. non alpha Color RBG consists of 3 bytes of information. Every byte is one Color with the order R(Red) B(Blue) G(Green) . 0xFF is one byte, if set to Red means that the Color has full red etc etc

0

精彩评论

暂无评论...
验证码 换一张
取 消