任何人都可以解釋如何從BufferedImage獲取rgb值的數組嗎?獲取BufferedImage的RGB
我在BufferedImage中有一個灰度圖像,需要提取一個描述圖像的0到255值的數組。
我知道BufferedImage是正確的,因爲我可以將它保存到PNG。但是,如果我使用int[] dataBuffInt = ((DataBufferInt) heightMap.getDataBuffer()).getData();
,我會得到一堆巨大的負數。
我已經搜索了一段時間,看到一些提及轉移一些值(post),但不真正明白他們在說什麼。
基本上我想從一個BufferedImage去一個0到255個RBG值的數組。
我不確定我是否正確解釋自己,plaese詢問更多細節是需要的。
編輯:
@Garbage謝謝你的提示。我試過int [] dataBuffInt = heightMap.getRGB(0,0,heightMap.getWidth(),heightMap.getHeight(),null,0,heightMap.getWidth());但獲得相同的結果。
@格雷格Kopff結果爲2,它被設置爲TYPE_INT_ARGB
BufferedImage.getType()的結果是什麼? –
您是否嘗試過http://docs.oracle.com/javase/6/docs/api/java/awt/image/BufferedImage.html#getRGB%28int,%20int,%20int,%20int,%20int [], %20int,%20int%29 – Garbage
@垃圾感謝您的提示。我試過int [] dataBuffInt = heightMap.getRGB(0,0,heightMap.getWidth(),heightMap.getHeight(),null,0,heightMap.getWidth());但獲得相同的結果。 – kotoko