This quick tutorial guides you on how to change SVG to PNG using C#. You will get crisp information to convert SVG into PNG using C# in the form of a step-wise procedure and a runnable sample code along with the directions to set the IDE environment. The sample code is the simplest one however you will be able to customize the process in a variety of ways and will also learn to save the output image not only as PNG but also in many other formats as well.
Steps to Transform SVG to PNG using C#
- Set the development environment to use Aspose.SVG for .NET from the NuGet package manager
- Load the source SVG file using the SVGDocument class object
- Create an object of ImageSaveOptions and set the format to PNG
- Save the SVG file as a PNG image using the ImageSaveOptions object with desired properties
These steps encompass the process to change a file from SVG to PNG using C# by using a few lines of code. First, you have to load the source SVG file and then save it in the desired format by setting the format from an enumerator. The SVGDocument class object is used to load the source SVG file whereas the ImageSaveOptions class object is used to customize the output image.
Code to Export SVG to PNG using C#
We can observe that the sample code converting an SVG to PNG using C# is too simple as only the SVG file is loaded and then using the ConvertSVG method it is saved in the desired PNG format. The ConvertSVG() method has more than 40 overloaded functions that can be used to convert an SVG file to a variety of formats. Also if you are only working with conversion to images, the ImageSaveOptions class object assists you to set the background color, format, page setup, smoothing mode, and a number of other properties also.
In this tutorial, we have learned to turn SVG into PNG using C# however if you want to learn the conversion of SVG to PDF, refer to the article on how to convert SVG to PDF in C#.