Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-5076878

ImageIO BMP Writer writes 32 bit files for 24 bit images

XMLWordPrintable

    • b77
    • x86
    • windows_xp

      Name: cc94850 Date: 07/21/2004


      FULL PRODUCT VERSION :
      java version "1.5.0-beta3"
      Java(TM) Runtime Environment, Standard Edition (build 1.5.0-beta3-b58)
      Java HotSpot(TM) Client VM (build 1.5.0-beta3-b58, mixed mode, sharing)

      A DESCRIPTION OF THE PROBLEM :
      Using ImageIO.write(RenderedImage, "BMP", File) you will get a BMP file representing a 32 bit image even when the source image is only 24 bits per pixel.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      A 24 bpp BMP file
      ACTUAL -
      A 32 bpp BMP file

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.Color;
      import java.awt.Graphics;
      import java.awt.Graphics2D;
      import java.awt.image.BufferedImage;
      import java.io.File;
      import java.io.IOException;

      import javax.imageio.ImageIO;

      /*
       * Created on Jul 21, 2004 by scottpalmer
       */

      /**
       * @author scottpalmer
       *
       */
      public class ImageIOBMP {

      public static void main(String[] args) throws IOException {
      // Create a 24-bit image
      BufferedImage img = new BufferedImage(720,480,BufferedImage.TYPE_INT_RGB);
      // give it some content
      Graphics2D g = (Graphics2D) img.getGraphics();
      g.setColor(Color.RED);
      g.fillOval(0,0,img.getWidth(),img.getHeight());
      g.setColor(Color.GREEN);
      g.fillOval(100,100,img.getWidth()-200,img.getHeight()-200);
      g.setColor(Color.BLUE);
      g.fillOval(200,200,img.getWidth()-400,img.getHeight()-400);
      g.dispose();

      // Write it out with ImageIO BMP writer
      String filename = "ShouldBe24Bit.bmp";
      String format = "BMP";

      ImageIO.write(img,format, new File(filename));

      System.out.println("Created \""+filename+"\"");
      System.out.println("Size should be about 1MB, if it is closer to 1.3MB an alpha channel was written.");;
      System.out.println("Size of \""+filename+"\" is "+new File(filename).length());
      }
      }

      ---------- END SOURCE ----------
      (Incident Review ID: 286713)
      ======================================================================

            bae Andrew Brygin
            campbell Christopher Campbell (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: