int rgbR;
int rgbG;
int rgbB;
int minx = 0;
int miny = 0;
try {
File file = new File("E:\\dd.png");
BufferedImage image = ImageIO.read(file);
int width = image.getWidth();//图片宽度
int height = image.getHeight();//图片高度
for (int i = minx; i < width; i++) {
for (int j = miny; j < height; j++) {
int pixel = image.getRGB(i, j); // 下面三行代码将一个数字转换为RGB数字
rgbR = (pixel & 0xff0000) >> 16;
rgbG = (pixel & 0xff00) >> 8;
rgbB = (pixel & 0xff);
System.out.println("i=" + i + ",j=" + j + ":(" + rgbR + "," + rgbG + "," + rgbB + ")");
}
}
System.out.println("图片宽度为:"+width+",高度为:"+height);
} catch (IOException e) {
System.out.println("读取文件出错");
e.printStackTrace();
}
温馨提示:答案为网友推荐,仅供参考