0

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.

Mr. Mike
  • 453
  • 5
  • 23
  • 1
    IDK why you would want to look at a color in terms of its binary values. The integer values seem more useful, see this question http://stackoverflow.com/questions/2534116/how-to-convert-get-rgbx-y-integer-pixel-to-colorr-g-b-a-in-java – ug_ Mar 26 '16 at 19:55

2 Answers2

3

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.

Paul Boddington
  • 37,127
  • 10
  • 65
  • 116
2

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.

fabian
  • 80,457
  • 12
  • 86
  • 114