输入一个BMP格式的图片,把每个像素的RGB值存入一个二维数组。

public static int[][] readBmp(InputStream in) throws IOException {
    BufferedImage image = ImageIO.read(in);

    if (image == null) {
        return null;
    }

    int width = image.getWidth();
    int height = image.getHeight();
    int[][] pixels = new int[width][height];

    for (int x = 0; x < width; x++) {
        for (int y = 0; y < height; y++) {
            pixels[x][y] = image.getRGB(x, y);
        }
    }

    return pixels;
}

 

posted @ 2022-07-13 15:04  dafengchui  阅读(83)  评论(0)    收藏  举报