2012-08-14 105 views
7

我使用setRGB()來改變圖像的像素值。java中的setRGB()

int rgb=new Color(0,0,0).getRGB(); 
image1.setRGB(i,j,rgb); //where i,j is the boundaries of the image 

在這裏,我將所有的像素值設置爲白色。但是這種變化並沒有在圖像中得到體現。任何人都知道setRGB()它是如何工作的?

+0

可能還有另外一個錯誤,或者你走了錯誤的方式。所以請發佈更多的代碼。 – reporter 2012-08-14 11:51:55

+2

幾點.. - 顏色(0,0,0)將是黑​​色 - setRGB設置圖像中的單個像素,而不是整個圖像 – Jimmy 2012-08-14 11:55:36

+0

rgb顏色圖表http://www.tayloredmktg.com/ rgb /#PA – 2012-08-14 11:56:01

回答

16

懷特是在RGB 255,255,255這樣:

Color myWhite = new Color(255, 255, 255); // Color white 
int rgb = myWhite.getRGB(); 

try { 
    BufferedImage img = null; 
    try { 
     img = ImageIO.read(new File("bubbles.bmp")); 
    } 
    catch (IOException e) { 
    } 

    for (int i = 0; i < 100; i++) { 
     for (int j = 0; j < 100; j++) { 
      img.setRGB(i, j, rgb); 
     } 
    } 

    // retrieve image 
    File outputfile = new File("saved.png"); 
    ImageIO.write(img, "png", outputfile); 
} 
catch (IOException e) { 
} 
+0

感謝您的回覆...我得到了我的錯誤 – Rohit 2012-08-14 13:57:39

+0

如果這回答你的問題,請接受它作爲答案,所以問題被標記爲回答。 – JeffC 2015-11-03 21:03:25

1
Color col = new Color(newValue, newValue, newValue); 
      image1.setRGB(i, j, col.getRGB()); 
相關問題