Convert SVG to PNG

Convert SVG to PNG

Aspose.Imaging for .NET 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.

using Aspose.Imaging;
using Aspose.Imaging.FileFormats.Svg;
using Aspose.Imaging.ImageOptions;
using System.IO;
string templatesFolder = @"c:\Users\USER\Downloads\templates\";
string dataDir = templatesFolder;
// Load the image
using (SvgImage image = (SvgImage)Image.Load(dataDir + "template.svg"))
{
// Create an instance of PNG options and Save the results to disk
PngOptions pngOptions = new PngOptions();
SvgRasterizationOptions svgOptions = new SvgRasterizationOptions();
svgOptions.PageWidth = 100;
svgOptions.PageHeight = 200;
pngOptions.VectorRasterizationOptions = svgOptions;
image.Save(dataDir + "result.png", pngOptions);
}
File.Delete(dataDir + "result.png");