了解BufferedImage.getRGB输出值 [英] Understanding BufferedImage.getRGB output values

查看:3465
本文介绍了了解BufferedImage.getRGB输出值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用此方法为图像中的像素获取整数值:

I'm getting an integer value for the pixel in an image using this method:

int colour = img.getRGB(x, y);

然后我打印出值,我看到黑色像素对应一个像 16777216,一种蓝色的东西像-16755216等等。有人可以解释一下这个值背后的逻辑吗?

Then I'm printing out the values and I see that black pixels correspond to a value like "-16777216", a kind of blue to something like "-16755216", etc. Can someone please explain me the logic behind this value?

推荐答案

getRGB(int x,int y)位置(x,y)的彩色像素。

您错误地解读了返回的值。

它是二进制格式。
喜欢11 ... 11010101,它作为int值赋给你。

如果你想得到它的值使用Color类。例如

getRGB(int x, int y) return you the value of color pixel at location (x,y).
You are misinterpreting the returned value.
It is in the binary format. like 11...11010101 and that is given to you as int value.
If you want to get its value use Color class. e.g.

Color mycolor = new Color(img.getRGB(x, y));

然后你可以使用 getRed ) getGreen() getBlue()

然后,这些方法将以熟悉的格式返回 int 值,其值 0 <值< 225

Then you can get red, green, or blue value by using getRed(), getGreen(), getBlue().
Then an int value will be returned by these methods in familiar format having value 0 < value < 225

int red = mycolor.getRed();

如果您不想使用 Color class,那么你将需要使用按位操作来获取它的值。

If you don't wants to use Color class then you will need to use bitwise operations to get its value.

这篇关于了解BufferedImage.getRGB输出值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆