JDK-6557713 : Java unable to convert from gif to png format
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.imageio
  • Affected Version: 5.0,5.0u12
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: solaris_10,windows_xp
  • CPU: x86,sparc
  • Submitted: 2007-05-15
  • Updated: 2011-03-07
  • Resolved: 2011-03-07
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other JDK 6 JDK 7
5.0u14Fixed 6u4Fixed 7 b14Fixed
Description
The issue appears to be the conversion routine in Java doesn't handle well transparent gifs, what the attached file is.

The test case outputs successful, but the outputted .png file can't be opened.
I have tested this with 1.4.2 and 1.5.0. Are transparent gifs supported?
I have tested another conversion tool and it was successful in converting this file.

import java.awt.image.RenderedImage;
import java.io.File;
import javax.imageio.ImageIO;


  //==========================================================
  // M A I N
  //==========================================================
public class Image {
  public static void main(String[] args) {
    String inputFile  = "sample.gif";
    String outputFile = "sample.png";
    try {
      RenderedImage image = ImageIO.read(new File(inputFile));
      if (ImageIO.write(image,"png", new File(outputFile)))
      {
        System.out.println("Image converted successfully");
      }
    }
    catch (Exception ex) {
        System.out.println("EXCEPTION OCCURED");
    }
  }
}

Comments
EVALUATION For given example GIF image reader produces 4 bpp indexed image with transparent pixel (bitmask transparency type). The peculiarity of this certain image is that it contains only grey pixels, i.e. for each pixel of image red component of pixel equals to green and blue components. Under these circumstances, PNG writer attempts to create png image with color type "Greyscale with alpha" (0x4). However, it is not correct because allowed bit depth for such color space is only 8 or 16 whereas given image has 4. So, to resolve this problem we should check the bit depth and create indexed png image if bit depth does not fits the "Greyscale with alpha" color type conditions.
16-05-2007

EVALUATION Possible duplicate of 6371389?
15-05-2007