title: Why doesn't ImageIO read a BMP file until it is re-saved in MS Paint?
body: <p>I have a bitmap file, <code>test3.bmp</code>, which I can view and edit with every image viewer I have tested with.</p>
  
  <p>That said, I cannot read it into my Java application. If I edit the BMP in MS Paint, save it, undo the change, and save it (<code>test3_resaved.bmp</code>), I have the same image, but with a different file size. The different file sizes do not concern me... what does, is that my application can read the re-saved file.</p>
  
  <p>Could anyone enlighten me on why one image works with my code but the other does not? </p>
  
  <p>Images files:</p>
  
  <ul>
  <li><p><a href="https://docs.google.com/leaf?id=0B8Ufd7Rk6dvHODM0OTk5ODEtMWEzMC00YzA1LTliMjQtZmNmNTdkNDA2YWIz&amp;hl=en_US">test3.bmp</a></p></li>
  <li><p><a href="https://docs.google.com/leaf?id=0B8Ufd7Rk6dvHMjk3NGIyOWEtNjk2MS00MmRkLThkYjktMDFmNTNlZmFhMGNk&amp;hl=en_US">test3_resaved.bmp</a></p></li>
  </ul>
  
  <p>Here is a minimal test application:</p>
  
  <pre><code>package Test;
  
  import java.awt.Graphics;
  import java.awt.Graphics2D;
  import java.awt.image.BufferedImage;
  import java.io.File;
  import java.io.IOException;
  
  import javax.swing.ImageIcon;
  import javax.swing.JFrame;
  
  @SuppressWarnings("serial")
  public class Test extends JFrame {
      private ImageIcon imageIcon;
  
      public Test(String filename) throws IOException {
          super();
          BufferedImage image = javax.imageio.ImageIO.read(new File(filename));
          imageIcon = new ImageIcon(image);
          setVisible(true);
          setDefaultCloseOperation(DISPOSE_ON_CLOSE);
          repaint();
      }
  
      public void paint(Graphics g) {
          Graphics2D g2d = (Graphics2D) g;
          setSize(imageIcon.getIconWidth(), imageIcon.getIconHeight());
          if (imageIcon != null)
              g2d.drawImage(imageIcon.getImage(), 0, 0, this);
      }
  
  
      /**
       * @param args
       */
      public static void main(String[] args) {
          try {
              if (args.length &gt; 0)
                  new Test(args[0]);
              else
                  System.out.println("usage - specify image filename on command line");
          }
          catch (Throwable t) {
              t.printStackTrace();
          }
      }
  
  }
  </code></pre>