2012-09-01 42 views
2

如何訪問索引圖像(png8或gif)的圖像數據(調色板索引數組)?獲取索引圖像的數據(調色板索引)

實施例:

  • 圖像調色板:{爲0xFF0000,0x00FF00,0x0000FF}
  • 圖像數據:{0,1,1,0,1,2,2,2,0,1,0 ,2,0,1,1,0}

我需要的是:

ArrayList<Integer> getImageData(File image) { 
    /* ??? */ 
} 
+0

順便說一句:'ArrayList '是錯誤的。泛型類必須使用引用類型進行輸入,並且必須*不能使用原始類型。你必須使用拳擊類'整數' - >'ArrayList '是正確的 – halex

+0

謝謝你,我已經糾正它。 – Aoshi

回答

0

下面的代碼將讀取的圖像數據進imageData,的陣列值。

BufferedImage image = ImageIO.read(imageFile); 
    int width = image.getWidth(); 
    int height = image.getHeight(); 
    int[] imageData = new int[width * height * image.getColorModel().getNumComponents()]; 
    imageData = image.getData().getPixels(0, 0, width, height, imageData); 
+0

謝謝,這正是我正在尋找的。 – Aoshi