输入一个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; }

浙公网安备 33010602011771号