United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6557713 Java unable to convert from gif to png format
JDK-6557713 : Java unable to convert from gif to png format

Details
Type:
Bug
Submit Date:
2007-05-15
Status:
Closed
Updated Date:
2011-03-07
Project Name:
JDK
Resolved Date:
2011-03-07
Component:
client-libs
OS:
solaris_10,windows_xp
Sub-Component:
javax.imageio
CPU:
x86,sparc
Priority:
P2
Resolution:
Fixed
Affected Versions:
5.0,5.0u12
Fixed Versions:

Related Reports
Backport:
Backport:

Sub Tasks

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

Possible duplicate of 6371389?
                                     
2007-05-15
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.
                                     
2007-05-16



Hardware and Software, Engineered to Work Together