码迷,mamicode.com
首页 > 编程语言 > 详细

【java】如何获得图片的像素点

时间:2017-11-14 19:38:02      阅读:364      评论:0      收藏:0      [点我收藏+]

标签:stat   eth   height   get   ++   而在   imageio   color   getwidth   

    public static int[][] getImageGRB(String filePath) {
        int[][] result=null;
        File file = new File(filePath);
        if (!file.exists()) {
            return result;
        }
        try {
            BufferedImage bufImg = ImageIO.read(file);
            int width = bufImg.getWidth();
            int height = bufImg.getHeight();
            result=new int[width][height];
            for(int i=0;i<height;i++){
                for(int j=0;j<width;j++){
                    result[i][j]=bufImg.getRGB(j,i)&0xFFFFFF;
                }
            }
        } catch (Exception e) {
        }
        return result;
    }

备注:因为使用getRGB(i,j)获取的该点的颜色值是ARGB,而在实际的应用中使用的的是RGB,所以需要将ARGB转化为RGB,即bufImg.getRGB(w,h)

【java】如何获得图片的像素点

标签:stat   eth   height   get   ++   而在   imageio   color   getwidth   

原文地址:http://www.cnblogs.com/HDK2016/p/7833841.html

(0)
(1)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!