Convert SVG to Raster image
Contents
[
Hide
]
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.
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
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"); |
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
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"); |