问题
i use image.getRGB(x,y); and the result is : -16777216
When i convert -16777216 to binary term, i get result :
1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 0000 0000 0000 0000 0000 0000
My question is, what the meaning for each binary above? (can you explain where is Red, Green, Blue, Alpha without using Color Class)
Thanks for help.
回答1:
You accidentally converted to 64 bit (long
) instead of 32 bit (int
).
The correct binary representation is
1111 1111 0000 0000 0000 0000 0000 0000
This value contains data for the 4 channels:
combined: 1111 1111 0000 0000 0000 0000 0000 0000
-----------------------------------------------------
alpha: 1111 1111
blue: 0000 0000
green: 0000 0000
red: 0000 0000
Which means this is a fully opaque black color.
回答2:
An int
has 32 bits, not 64
, so the bits of -16777216
are in fact
1111 1111 0000 0000 0000 0000 0000 0000
The first 8 bits are for alpha. The next 8 bits are for red. The next 8 bits are for green. The last 8 bits are for blue. For this colour:
alpha = 1111 1111 = 255
red = 0000 0000 = 0
green = 0000 0000 = 0
blue = 0000 0000 = 0
If all 3 RGB values are 0
it represents black. 255
is the maximum possible alpha value, meaning that the colour is not transparent at all.
来源:https://stackoverflow.com/questions/36240069/java-understanding-about-image-getrgbx-y-output-in-binary-term