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

ImageIO.read ignores alpha channel in PNG

XMLWordPrintable

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

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


      ADDITIONAL OS VERSION INFORMATION :
      Linux Brisbane 2.6.22-14-generic #1 SMP Tue Feb 12 07:42:25 UTC 2008 i686 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      It appears that some PNGs with an alpha channel, lose the alpha channel when loaded with ImageIO.read.

      The test code provided loads an image from a URL (the image is a PNG from a Web Map Server, which has transparency). If you open this same image in an image viewer application, you can see that it does indeed have a transparency.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile the ReproduceBug class, then run its main method.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Does image have an alpha channel? >> YES
      ACTUAL -
      Does image have an alpha channel? >> NO

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.imageio.ImageIO;
      import java.awt.image.BufferedImage;
      import java.io.IOException;
      import java.net.URL;

      public class ReproduceBug {

          public static void main(String[] args) {
              try {
              BufferedImage shouldHaveAlpha = ImageIO.read(new URL("http://www.webgis.nrm.qld.gov.au/wmsconnector/com.esri.wms.Esrimap/NAP_RIS_Portal" +
                          "?VERSION=1&SRS=EPSG%3A4326&transparent=true" +
                          "&request=GetMap&styles=&format=image%2Fpng&layers=naptwnp%2Croad25ml%2Cdrain25ml" +
                          "&bbox=139.11712858077894,-20.64651565636843,146.84497668237893,-14.20664223836843" +
                          "&width=32&height=32"));

                  System.out.println("Does image have an alpha channel? >> " +
                          ((shouldHaveAlpha.getAlphaRaster() == null) ? "NO" : "YES"));

              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      None as yet.

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

              Created:
              Updated:
              Imported:
              Indexed: