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

查看:61
本文介绍了了解 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)<的颜色像素值/strong>.
您误解了返回的值.
它是二进制格式.像 11...11010101,它作为整数值提供给你.
如果您想获得该值的 RGB(即红色、绿色、蓝色)分量,请使用 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 RGB (i.e. Red, Green, Blue) components of that value use Color class. e.g.

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

然后你可以通过使用getRed()getGreen()getBlue()、<代码>getAlpha().然后这些方法会以熟悉的格式返回一个 int 值,其值为 0 <值<255

Then you can get Red, Green, or Blue value by using getRed(), getGreen(), getBlue(), getAlpha(). Then an int value will be returned by these methods in familiar format having value 0 < value < 255

int red = mycolor.getRed();

如果您不想使用 Color 类,那么您将需要使用按位运算来获取其值.

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

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

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