1. 程式人生 > >【java】如何獲得圖片的像素點

【java】如何獲得圖片的像素點

exce buffered 獲得 色值 edi 如何 ati div buffere

    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】如何獲得圖片的像素點