2013-03-08 79 views
0

我還沒有進入圖像處理。 我想在JAVA中讀取.jpeg圖像文件,並根據顏色值在畫布上繪製像素。 即首先繪製所有黑色像素,然後繪製所有灰色像素,以此類推.....以及結束時的白色像素。在java中以像素爲單位繪製圖像

我也想引入繪製每個像素之間的一個非常小的差距,以便我可以看到圖像如何繪製。

任何幫助,將不勝感激。

+0

你只想要黑色和白色?還是全色譜? – 2013-03-08 15:32:42

回答

2

這是一個簡短的,精簡的指令示例,可以幫助您入門。該代碼分解了圖像中的RGB值。然後,您可以做任何您需要的數據。

public static BufferedImage exampleForSO(BufferedImage image) { 
    BufferedImage imageIn = image; 
    BufferedImage imageOut = 
    new BufferedImage(imageIn.getWidth(), imageIn.getHeight(), BufferedImage.TYPE_4BYTE_ABGR); 
    int width = imageIn.getWidth(); 
    int height = imageIn.getHeight(); 
    int[] imageInPixels = imageIn.getRGB(0, 0, width, height, null, 0, width); 
    int[] imageOutPixels = new int[imageInPixels.length]; 
    for (int i = 0; i < imageInPixels.length; i++) { 
     int inR = (imageInPixels[i] & 0x00FF0000) >> 16; 
     int inG = (imageInPixels[i] & 0x0000FF00) >> 8; 
     int inB = (imageInPixels[i] & 0x000000FF) >> 0; 

     if ( conditionChecker_inRinGinB ){ 
      // bla bla bla 
     } else { 
      // yada yada yada 
     } 

    } 
    imageOut.setRGB(0, 0, width, height, imageOutPixels, 0, width); 
    return imageOut; 
}