title: How to get RGB values using Java
body: <p>I'm trying to get the pixels in RGB format of an image. I have the following code:   </p>
  
  <pre><code>public void writeColorImageValueToFile(BufferedImage in, String fileName)   
      {   
      int width = in.getWidth();   
      int height = in.getHeight();   
  
      try   
      {   
          FileWriter fstream = new FileWriter(fileName + ".txt");   
          BufferedWriter out = new BufferedWriter(fstream);   
  
          int [] data = new int[width * height];      
          in.getRGB(0, 0, width, height, data, 0, width);   
  
          for(int i = 0; i &lt; (height * width); i++)   
          {                        
              out.write(((data[i] &gt;&gt; 16) &amp; 0xff) + ", ");    
              out.write(((data[i] &gt;&gt; 8) &amp; 0xff) + ", ");   
              out.write((data[i] &amp; 0xff) + "\n");   
          }   
  
          out.close();   
      } catch (Exception e)   
      {   
          System.err.println("Error: " + e.getMessage());   
      }   
  }   
  </code></pre>
  
  <p>I created an image in photoshop and I filled it with the color RGB(86, 136, 152), however I got from my java method the value of RGB(44, 139, 154).   </p>
  
  <p>I load the image using:   </p>
  
  <pre><code>BufferedImage img = ImageIO.read(new File("blue.jpg"))    
  </code></pre>
  
  <p>I don't know what I'm doing wrong.   </p>
  
  <p>Any suggestion?   </p>