Convert SVG to PNG
Contents
[
Hide
]
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); | |
} |