title: Why Java ImageIO flattens JPEG colors
body: <p>When I read certain JPG files, colors are flattened. Here is a simple example that reads a jpg and just writes the same image to another file.</p>
  
  <pre><code>import java.awt.image.BufferedImage;
  import java.io.File;
  import javax.imageio.ImageIO;
  
  public class JPegReadTest {
      public static void main(String[] args) {
          if (args.length == 2) {
              try {
                  BufferedImage src = ImageIO.read(new File(args[0]));
                  ImageIO.write(src, "jpg", new File(args[1]));
              } catch (Exception e) {
                  e.printStackTrace();
              }
          } else {
              System.err.println("Usage: java JPegReadTest src dest");
          }
      }
  }
  </code></pre>
  
  <p>If you try this with for example <a href="http://www.flickr.com/photos/visualpanic/233508614/sizes/l/" rel="noreferrer">http://www.flickr.com/photos/visualpanic/233508614/sizes/l/</a> , the colors of the destination image differ from the source file. Why is that? How to fix it?</p>
  
  <p>Also tried saving the image as png, but the colors are bland in it too (so assuming color info is not read properly).</p>