【发布时间】:2013-06-09 23:51:48
【问题描述】:
类似于以下内容...除了让它工作:
public void seeBMPImage(String BMPFileName) throws IOException {
BufferedImage image = ImageIO.read(getClass().getResource(BMPFileName));
int[][] array2D = new int[66][66];
for (int xPixel = 0; xPixel < array2D.length; xPixel++)
{
for (int yPixel = 0; yPixel < array2D[xPixel].length; yPixel++)
{
int color = image.getRGB(xPixel, yPixel);
if ((color >> 23) == 1) {
array2D[xPixel][yPixel] = 1;
} else {
array2D[xPixel][yPixel] = 1;
}
}
}
}
【问题讨论】:
-
那么上面的代码有什么问题呢?
-
你为什么要测试
if((color >> 23) == 1)?这会测试红色分量是否为 128 或更多。 -
您可以简单地从RGB
int值构造一个Color对象并直接获取red、green、blue值... -
为什么要在 if-branch 和 else-branch 中分配 1?可能是一个错误......