int a = bufferedImageSource.getRGB(x,y) 的值是多少?

What will be the value of int a = bufferedImageSource.getRGB(x,y)?

我有点困惑到底什么值将存储在变量 a 中。请有人能举例说明一下吗

提前致谢。

正如 BufferedImage.getRGB() 文档所说:

Returns an integer pixel in the default RGB color model (TYPE_INT_ARGB) and default sRGB colorspace. Color conversion takes place if this default model does not match the image ColorModel. There are only 8-bits of precision for each color component in the returned data when using this method.

要将其划分为 R、G、B 值,您可以使用按位运算:

BufferedImage bufferedImage = new BufferedImage(10, 10, 10);
int a = bufferedImage.getRGB(0, 0);

int red = (a >> 16) & 255;
int green = (a >> 8) & 255;
int blue = (a) & 255;
System.out.println(a + " r:" + red + ", g:" + green + ", b:" + blue);