I'm using JMyron
in a webcam app written in Java, and the program returns what the webcam is seeing as an int []
. Since it's one pixel per int, how does it repres开发者_运维技巧ent the rgb
values of the pixel as one int?
An int is 32 bits. So the first 8 bits of the int are red 0-255, the second 8 bits are green 0-255, the third 8 bits are blue 0-255, and the last 8 bits are the alpha value 0-255.
That's why it's called 32-bit color. It blew my mind when I first connected the dots.
Java's Color can do so as well:
'Color.getRGB()'
Different bits of the int represent the different color component values. You may extract them yourself, or use the Color class to do so:
Color c = new Color(imageRGB);
int red = c.getRed();
int green = c.getGreen();
...
精彩评论