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

BMP writer won't write 32-bit images

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 6
    • client-libs

      FULL PRODUCT VERSION :
      java version "1.6.0_10-beta"
      Java(TM) SE Runtime Environment (build 1.6.0_10-beta-b22)
      Java HotSpot(TM) Client VM (build 11.0-b11, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      ImageIO won't write a 32 bit BMP image. This is sad, since there used to be a bug where it would write 32-bit image files from 24-bit image objects. See Bug# 5076878 .




      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      ImageIO.write(RenderedImage, "BMP", File) will fail in the RenderedImage is a BufferedImage created with new BufferedImage(width, height,BufferedImage.TYPE_INT_ARGB);



      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      A 32-bit BMP file should be written, specially since this used to happen for 24-bit images as per bug # 5076878
      ACTUAL -
      Can't write 32-bit BMP images

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.Color;
      import java.awt.Font;
      import java.awt.Graphics2D;
      import java.awt.RenderingHints;
      import java.awt.image.BufferedImage;
      import java.io.File;
      import java.io.IOException;
      import java.util.Iterator;
      import javax.imageio.ImageIO;
      import javax.imageio.ImageTypeSpecifier;
      import javax.imageio.ImageWriter;
      import javax.imageio.stream.FileImageOutputStream;

      public class Main {

          public static void main(String[] args) throws IOException {
      int width = 720;
      int height = 480;
      int size = 36;
      int x = 20;
      int baseline = 400;
      Color textColor = Color.WHITE;
      String msg = "Hello World";
      Font font = new Font("Tahoma", Font.PLAIN, size);
              BufferedImage bi = new BufferedImage(width, height,BufferedImage.TYPE_INT_ARGB);
      Graphics2D g = bi.createGraphics();
      g.setColor(textColor);
      g.drawString(msg, x, baseline);
      g.dispose();

      System.out.println("\nKnown format names:");
      for (String fn : ImageIO.getWriterFormatNames()) {
      System.out.println(fn);
      }

      Iterator<ImageWriter> iwi = ImageIO.getImageWriters(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_ARGB), "BMP");

      int i = 0;
      while ( iwi.hasNext()) {
      ImageWriter iw = iwi.next();
      try {
      iw.setOutput(new FileImageOutputStream(new File ("title"+i+".bmp")));
      iw.write(bi);
      System.out.println("Wrote image using "+iw);
      i++;
      } catch(Exception ex) {
      System.err.println(ex.getLocalizedMessage());
      System.err.println("Can't write with "+iw);
      }
      }
      if (i == 0) // try this way too
      ImageIO.write(bi, "BMP", new File("test.bmp")) ;
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Use PNG

            jdv Jayathirth D V
            igor Igor Nekrestyanov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: