java中的setRGB()

我正在使用setRGB()来更改图像像素的值。

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

在这里,我将所有像素值设置为白色。 但这种变化并没有反映在图像中。 任何人都知道setRGB()它是如何工作的?

白色是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) { } 
  Color col = new Color(newValue, newValue, newValue); image1.setRGB(i, j, col.getRGB());