SVG "The image is not a RasterImage type"

I tried to convert SVG to PNG with Aspose.Imaging Java 17.9.
SvgImage image = new SvgImage(inputStream);
image.save(outputStream, new PngOptions());
It throws the exception
com.aspose.imaging.internal.Exceptions.ArgumentException: The image is not a RasterImage type.
at com.aspose.imaging.internal.dO.bc.a(Unknown Source)
at com.aspose.imaging.internal.dO.bc.(Unknown Source)
at com.aspose.imaging.fileformats.svg.SvgImage.(Unknown Source)
at com.aspose.imaging.fileformats.svg.SvgImage.(Unknown Source)
The inputStream is read from a valid SVG file. I’m confused, SVG is vector, but the exception message suggests SvgImage constructor expects raster?

@psfung,

I have observed your comments. Can you please share sample project along with source files and environment details so that we can further investigate to help you out. Before sharing requested information i suggest you to please try to use Aspose.Imaging latest version 18.2 on your end.

Hi please try this class with sample svg. 18.2 is the same.
svg2png.zip (13.6 KB)

Image.load() works:

Image image = Image.load(inputStream, new SvgLoadOptions());
image.save(outputStream, new PngOptions());

@psfung,

I have used following sample code using Aspose.Imaging for Java 18.2 on my end and it has generated a PNG file without any issue on my end. Can you please try using following code with suggested version. I have also attached generated output for reference as well.

public static void SVGtoPNG()
{

    String path="C:\\Imaging Data\\svg2png\\";
    // Create an instance of Image class and load an exiting SVG file.
    com.aspose.imaging.Image image = com.aspose.imaging.Image.load(path + "s1.svg");

    // Cast image object to SVG image
    com.aspose.imaging.fileformats.svg.SvgImage svgImage = (com.aspose.imaging.fileformats.svg.SvgImage) image;

    // Create an instance of PngOptions class
    com.aspose.imaging.imageoptions.PngOptions pngOptions = new com.aspose.imaging.imageoptions.PngOptions();

    // convert and save to disk in PNG file format.
    svgImage.save(path + "out.png", pngOptions);

}

out.png (3.9 KB)

Yes, that works. Thanks.