title: changing image color in java
body: <p>I am trying to change color of image. Hence I used the following code</p>
  
  <pre><code>public class Picture {
  
  String img_name;
  BufferedImage buf_img;
  int width;
  int height;
  
  public Picture(String name) {
      this.img_name = name;
  
      try {
          buf_img = ImageIO.read(new File(img_name));
      } catch (IOException ex) {
          Logger.getLogger(Picture.class.getName()).log(Level.SEVERE, null, ex);
      }
  }
  
  public Picture(int w, int h) {
      this.width = w;
      this.height = h;
      buf_img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
  }
  
  public int width() {
      width = buf_img.getWidth();
      return width;
  }
  
  public int height() {
      height = buf_img.getHeight();
      return height;
  }
  
  public Color get(int col, int row) {
      Color color = new Color(buf_img.getRGB(col, row));
      return color;
  }
  
  public void set(int col, int row, Color color) {
      buf_img.setRGB(col, row, color.getRGB());
  }
  
  public void show() {
      try {
  
          File saveAs = new File("D:\\temp\\" + new Random().nextInt() + ".png");
          ImageIO.write(buf_img, "png", saveAs);
  
          Desktop.getDesktop().open(saveAs);
      } catch (IOException ex) {
          Logger.getLogger(Picture.class.getName()).log(Level.SEVERE, null, ex);
      }
     }
  
   }
  
  public class ColorSeparation {
  
  public static void main(String[] args) {
  
      // read in the picture specified by command-line argument
      Picture picture = new Picture("D:\\qwe1.jpg");
      int width = picture.width();
      int height = picture.height();
  
      // create three empy pictures of the same dimension
      Picture pictureR = new Picture(width, height);
  
  
      // separate colors
      for (int col = 0; col &lt; width; col++) {
          for (int row = 0; row &lt; height; row++) {
              Color color = picture.get(col, row);
              int r = color.getRed();
              int g = color.getGreen();
              int b = color.getBlue();
              pictureR.set(col, row, new Color(r, 0, 0));
  
          }
      }
  
      // display  picture in its own window
      pictureR.show();
  
    }
  
  }
  </code></pre>
  
  <p>It is working as expected. <a href="https://i.stack.imgur.com/yy1Ya.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yy1Ya.jpg" alt="input Image"></a></p>
  
  <p><a href="https://i.stack.imgur.com/nIFFx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nIFFx.png" alt="Output image"></a>.</p>
  
  <p>Now I want to set color of entire image to rgb 255, 153, 51. I tried to set
  <code>pictureR.set(col, row, new Color(255, 153, 51))</code>. But the resulted output is the below image<a href="https://i.stack.imgur.com/FVKYQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FVKYQ.png" alt="resulting image"></a>. </p>
  
  <p>How can I get correct image? Please help.</p>