I am trying to convert a CGM file to PNG using below function. I am keep getting NullPointerException.
public File convertCGMtoPNG(File cgmFile, File directoryToCreatePNG,
String nameSuffix) throws IOException
{
File pngFile = new File(directoryToCreatePNG.getAbsolutePath() +
File.separator +
cgmFile.getName().substring(0,cgmFile.getName().lastIndexOf(".cgm")) +
"_" + nameSuffix + ".png");
BufferedImage image = ImageIO.read(cgmFile);
ImageIO.write(image, "PNG", pngFile);
return pngFile;
}
Below is the Exception i am facing
java.lang.IllegalArgumentException: image == null! at java.desktop/javax.imageio.ImageTypeSpecifier.createFromRenderedImage(ImageTypeSpecifier.java:925)
at java.desktop/javax.imageio.ImageIO.getWriter(ImageIO.java:1608)
at java.desktop/javax.imageio.ImageIO.write(ImageIO.java:1540)
I tried to debug the code and came to know that the CGM format is not supported by ImageIO (CanDecodeInputFilter returns false for my CGM). Any idea on how to convert a CGM to PNG image.
PS: I am using java 11 for my development.
Thanks in advance
Update
Based on the replies I tried jcgm libraries(added the core and image libraries to my classpath). It passes through the "image == null!" error but now throwing below error
java.lang.IllegalArgumentException: width*height > Integer.MAX_VALUE!
at java.desktop/javax.imageio.ImageReader.getDestination(ImageReader.java:2821)
at net.sf.jcgm.imageio.plugins.cgm.CGMImageReader.read(Unknown Source)
at java.desktop/javax.imageio.ImageIO.read(ImageIO.java:1468)
at java.desktop/javax.imageio.ImageIO.read(ImageIO.java:1315)
Still struggling to make it work.