What is the meaning of a negative number when usin

2019-06-28 08:32发布

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.

2条回答
一纸荒年 Trace。
2楼-- · 2019-06-28 08:55

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.

查看更多
SAY GOODBYE
3楼-- · 2019-06-28 08:55

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();
查看更多
登录 后发表回答