public class ImageRead {
int width=0;
int height=0;
int[][] ImageArray;
StringBuffer sb = new StringBuffer();
public int[][] getImagePixel(String image) throws IOException {
//读取图片文件
File file = new File(image);
BufferedImage bi = null;
try {
bi = ImageIO.read(file);
} catch (Exception e) {
e.printStackTrace();
}
//得到图片像su的宽和高
width = bi.getWidth();
height = bi.getHeight();
ImageArray = new int[width][height];
System.out.println("width=" + width + ",height=" + height + ".");
//输出每一个像素点的color
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
//i,j位置的Color值
int pixel = bi.getRGB(i, j);
sb.append(pixel);
ImageArray[i][j]=pixel;
}
sb.append("\r\n");
}
writeFile(sb.toString());
return ImageArray;
}
}