I am new to color stuff, rendering etc. and watching a couple tutorial videos about rendering etc. My question is, when I call a getRGB
method on a pixel, it returns a negative int. what is the meaning of this negative number? For example, when i call getRGB
on a color with r: 186, g: 186, b: 186, it returns -4539718. How is this number related to its rgb value? I've made a couple of google search but was not successful.
The getRGB
method returns an int
whose 4 bytes are the alpha, red, green, and blue components in that order. Assuming that the pixel is not transparent, the alpha is 255 (0xFF). It's the most significant byte in the int
, and the first bit is set in that value. Because in Java int
values are signed according to Two's Complement, the value is actually negative because that first bit is on.
To get the color of a pixel:
Color c = new Color(image.getRGB(10,10));
int red = c.getRed();
int green = c.getGreen();
int blue = c.getBlue();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With