Convert SVG to PNG

Convert SVG to PNG

Aspose.Imaging for Java provides the SvgImage class to load SVG files and same can be used to save the image to PNG format.

Below provided sample code demonstrate how to convert SVG to PNG.

// Load the image
Image image = Image.load(dataDir + "aspose-logo.svg");
try
{
// Create an instance of PNG options
PngOptions pngOptions = new PngOptions();
SvgRasterizationOptions svgOptions = new SvgRasterizationOptions();
svgOptions.setPageWidth(100);
svgOptions.setPageHeight(200);
pngOptions.setVectorRasterizationOptions(svgOptions);
// Save the results to disk
image.save(dataDir + "ConvertingSVGToRasterImages_out.png", pngOptions);
}
finally
{
image.close();
}