到目前为止,我有以下代码可以读取 30x40 像素的 .bmp 文件:
public void setUp() throws IOException
{
BufferedImage image =
ImageIO.read(getClass().getResource("circle1.bmp"));
greenInputData = new byte[30][40];
for (int x = 0; x < greenInputData.length; x++)
{
for (int y = 0; y < greenInputData[x].length; y++)
{
int color = image.getRGB(x, y);
greenInputData[x][y] = (byte)(color >> 8);
}
}
System.out.println(greenInputData);
}
当我调用 System.out.println(greenInputData) 时,控制台现在给了我以下信息:
[[B@1c8a1c9d [[B@1cb4ee66 [[B@262580b3 [[B@450a3962 [[B@5d7138f4 [[B@44443799] [[B@5220c1b [[B@52c4d93 [[B@3eaa2c1c [[B@2b3fc0bb [[B@4b8b7245 [[B@2623592 [[B@e689490 [[B@3849ca75] [[B@ebe5687 [[B@671ef55c [[B@68c6fc84 [[B@53dc5341
但我希望能够看到我正在阅读的图像的数组打印输出。例如,如果我读取一个圆的位图,我希望能够 System.out.println() 输出一个 30x40 位图数组,如下所示:
<---------30---------------->
000000000000000000000000000000 ^
000000111110000000000000000000 |
000001111111100000000000000000 |
000011111111110000000000000000 |
000011111111110000000000000000 40
000001111111100000000000000000 |
000000011110000000000000000000 |
000000000000000000000000000000 |
000000000000000000000000000000 |
.
.
.