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

attempt to save buffered image to bmp file fails silently in case of types: TYPE_INT_ARGB, TYPE_INT_ARGB_PRE, TYPE_4BYTE_ABGR, 4BYTE_ABGR_PRE

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • 9
    • 6.0, 7, 8, 9
    • client-libs
    • None

      OS: Ubuntu 14 Linux, JDK9 b100, JDK8 b132

      Please run the following test:

      import java.awt.*;
      import java.awt.image.BufferedImage;
      import java.io.*;
      import javax.imageio.ImageIO;

      public class Test {

          public static void main(String[] args) throws IOException {
              testWrite("bmp", BufferedImage.TYPE_INT_RGB);
              testWrite("bmp", BufferedImage.TYPE_INT_ARGB);
              testWrite("bmp", BufferedImage.TYPE_INT_BGR);
              testWrite("bmp", BufferedImage.TYPE_INT_ARGB_PRE);
          }

          private static final String[] biTypeNames = {
              "CUSTOM", "INT_RGB", "INT_ARGB", "INT_ARGB_PRE", "INT_BGR", "3BYTE_BGR",
              "4BYTE_ABGR", "4BYTE_ABGR_PRE", "USHORT_565_RGB", "USHORT_555_RGB",
              "BYTE_GRAY", "USHORT_GRAY", "BYTE_BINARY", "BYTE_INDEXED"};


          private static void testWrite(String format, int type) throws IOException {

              BufferedImage bi = new BufferedImage(100, 100, type);
              Graphics2D g = bi.createGraphics();
              g.setColor(Color.GREEN);
              g.fillRect(0, 0, 100, 100);

              String name = "Test_" + biTypeNames[type] + "." + format;
              System.out.println("Creating " + name);
              ImageIO.write(bi, format, new File(name));
          }
      }

      Output:
      Creating Test_INT_RGB.bmp
      Creating Test_INT_ARGB.bmp
      Creating Test_INT_BGR.bmp
      Creating Test_INT_BGR_PRE.bmp

      "echo $?" returns 0, no exceptions are thrown, but only 2 files are created:
      Test_INT_BGR.bmp
      Test_INT_RGB.bmp
      (Test_INT_ARGB.bmp, Test_INT_ARGB_PRE.bmp are absent)

            jdv Jayathirth D V
            avstepan Alexander Stepanov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: