问题描述
我有这个简单的代码通过24位彩色windows bmp文件
I have this simple code to go through a 24bit color windows bmp file
BufferedImage mapa = BMPDecoder.read(new File("maps/map.bmp"));
final int xmin = mapa.getMinX();
final int ymin = mapa.getMinY();
final int ymax = ymin + mapa.getHeight();
final int xmax = xmin + mapa.getWidth();
for (int i = xmin;i<xmax;i++)
{
for (int j = ymin;j<ymax;j++)
{
int pixel = mapa.getRGB(i, j);
if (pixel == 0)
{
System.out.println("black at "+i+","+j);
}
}
}
然而,当测试时完全黑色的图像,我得到像素的这个值: -16777216
。
However, when testing on a completely black image, I get this value at pixel : -16777216
.
我希望得到一个0x0。
I was hoping to get a 0x0.
我如何测试黑色像素(或任何其他颜色)?
How can I test for black pixels (or any other color for that reason) ?
我正在测试((像素& 0xff)== 0)
。这是正确的吗?
提前致谢。
Im testing against ((pixel & 0xff) == 0)
. Is this right?Thanks in advance.
推荐答案
-16777216
是 0xFF000000
十六进制,对应于不透明的黑色。
-16777216
is 0xFF000000
in hexadecimal, corresponding to opaque black.
附录:看看你的更新,我想你想要((像素& 0x00FFFFFF)== 0)
作为您的谓词。
Addendum: Looking at your update, I'd think you want ((pixel & 0x00FFFFFF) == 0)
as your predicate.
这篇关于java Buffered Image:检测黑色像素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!