/**
java获取图片每个像素点的RGB
原创
©著作权归作者所有:来自51CTO博客作者TinyKing的原创作品,请联系作者获取转载授权,否则将追究法律责任
* 获取图片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。
下一篇: 通过两个点的经纬度计算距离
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
AI作画
AI画作的原理,含简单代码示例
ide tensorflow 编码器

















