Java - Understanding about image.getRGB(x,y) output in Binary term

好久不见. 提交于 2019-12-25 08:46:12

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!