Convert SVG to Raster image

Convert SVG to Raster image

Using Aspose.Imaging for .NET, developers can convert SVG (Scalable Vector Graphics) to raster formats. This article shows how to export/convert SVG file to raster image formats with Aspose.Imaging. Aspose.Imaging for .NET provides the SvgImage class to load SVG files and same can be used to convert the SVG to raster formats.

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");
using Aspose.Imaging;
using Aspose.Imaging.ImageOptions;
using System.IO;
string templatesFolder = @"c:\Users\USER\Downloads\templates\";
string dataDir = templatesFolder;
using (Image image = Image.Load(dataDir + "template.svg"))
{
BmpOptions options = new BmpOptions();
SvgRasterizationOptions svgOptions = new SvgRasterizationOptions();
svgOptions.PageWidth = 100;
svgOptions.PageHeight = 200;
options.VectorRasterizationOptions = svgOptions;
image.Save(dataDir + "result.bmp", options);
}
File.Delete(dataDir + "result.bmp");