/**
* 获取图片RGB数组
* @param filePath
* @return
*/
public int[][] getImageGRB(String filePath) {
File file = new File(filePath);
int[][] result = null;
if (!file.exists()) {
return result;
}
try {
BufferedImage bufImg = ImageIO.read(file);
int height = bufImg.getHeight();
int width = bufImg.getWidth();
result = new int[width][height];
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
result[i][j] = bufImg.getRGB(i, j) & 0xFFFFFF;
System.out.println(bufImg.getRGB(i, j) & 0xFFFFFF);
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}
备注:应为使用getRGB(i,j)获取的该点的颜色值是ARGB,而在实际应用中使用的是RGB,所以需要将ARGB转化成RGB,即bufImg.getRGB(i, j) & 0xFFFFFF。
本文出自 “TinyKing” 博客,请务必保留此出处http://tinyking.blog.51cto.com/3338571/749045
* 获取图片RGB数组
* @param filePath
* @return
*/
public int[][] getImageGRB(String filePath) {
File file = new File(filePath);
int[][] result = null;
if (!file.exists()) {
return result;
}
try {
BufferedImage bufImg = ImageIO.read(file);
int height = bufImg.getHeight();
int width = bufImg.getWidth();
result = new int[width][height];
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
result[i][j] = bufImg.getRGB(i, j) & 0xFFFFFF;
System.out.println(bufImg.getRGB(i, j) & 0xFFFFFF);
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}
备注:应为使用getRGB(i,j)获取的该点的颜色值是ARGB,而在实际应用中使用的是RGB,所以需要将ARGB转化成RGB,即bufImg.getRGB(i, j) & 0xFFFFFF。
本文出自 “TinyKing” 博客,请务必保留此出处http://tinyking.blog.51cto.com/3338571/749045