`
xiangxingchina
  • 浏览: 506273 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

java获取图片每个像素点的RGB

 
阅读更多
/**


      * 获取图片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
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics