SetRGB () in java

I use setRGB () to change the pixel values ​​of an image.

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

Here I set all pixel values ​​with white color. But the change does not affect the image. setRGB() anyone know about setRGB() how it works?

+7
source share
2 answers

White is in RGB 255,255,255, therefore:

 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) { } 
+16
source
  Color col = new Color(newValue, newValue, newValue); image1.setRGB(i, j, col.getRGB()); 
+1
source

All Articles