/**
* 获取图片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。
转载于:https://blog.51cto.com/tinyking/749045