像下面......除了使其工作:
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;
}
}
}
}
最佳答案
我会用这个:
public void seeBMPImage(String BMPFileName) throws IOException {
BufferedImage image = ImageIO.read(getClass().getResource(BMPFileName));
int[][] array2D = new int[image.getWidth()][image.getHeight()];
for (int xPixel = 0; xPixel < image.getWidth(); xPixel++)
{
for (int yPixel = 0; yPixel < image.getHeight(); yPixel++)
{
int color = image.getRGB(xPixel, yPixel);
if (color==Color.BLACK.getRGB()) {
array2D[xPixel][yPixel] = 1;
} else {
array2D[xPixel][yPixel] = 0; // ?
}
}
}
}
它向您隐藏了RGB的所有细节,并且更易于理解。