SVG to PNG Conversion using C#

SVG is one of the most used formats for website building and print graphics to achieve scalability. But sometimes, you need to convert SVG and save it in a common raster image format. With Aspose.SVG for .NET API, you can transform SVG to PNG programmatically with full control over a wide range of conversion parameters. Powerful C# API allows you to convert SVG to other popular formats with high speed and high quality. Convert SVG files to PNG, making it easy to share, collaborate, and present visual content across devices and platforms!


Free Online Converter

Test the quality of SVG to PNG conversion right in your browser! The following C# example demonstrates how to convert an SVG document using ConvertSVG() method. We describe the source code for reading SVG from a file and then converting SVG to PNG with default saving options. Please load SVG from the local file system, select the output format and run the example. You will immediately get the result as a separate file.

Please visit our Documentation to learn more about using Aspose.SVG API conversion functions and to consider C# examples for the most common SVG conversion scenarios. In the documentation article Convert SVG to Image , you can consider C# examples of how to convert SVG to images in different ways. Let’s consider some of them:


Steps to Convert SVG to PNG using ConvertSVG() Method

  1. Load an SVG file using one of the SVGDocument() constructors of the SVGDocument class.
  2. Create a new ImageSaveOptions object. By default, the Format property is PNG.
  3. Use the ConvertSVG() method to save SVG as a PNG image. You need to pass the SVGDocument, ImageSaveOptions, and output file path to the ConvertSVG() method.
  4. The PNG file will be saved to the specified path.

Steps to Convert SVG to PNG using RenderTo() Method

  1. Initialize SVGDocument with your SVG file.
  2. Create an object of the ImageRenderingOptions class. Use the ImageRenderingOptions() constructor and specify the Format property of the document.
  3. Initialize ImageDevice class and specify the output file name to render.
  4. Call RenderTo() method & pass the instance of the ImageDevice.

Convert SVG to PNG

using (var document = new SVGDocument("input.svg"))
{
	var options = new ImageRenderingOptions(ImageFormat.Png);
	using (IDevice device = new ImageDevice(options, "output.png"))
	{
		document.RenderTo(device);
	}
}

FAQ

1. How can I convert SVG to PNG?

Aspose.SVG allows you to convert SVG to other formats in any way – online or programmatically. You can convert SVG in real-time using SVG Converter, which transforms your files quickly and with high quality. Upload, convert SVG and get results in a few seconds. Alternatively, you can use Aspose.SVG for .NET API and the provided C# code to convert SVG to PNG programmatically.

2. Why should I convert SVG?

Vector graphics is one of the most popular Web design trends in recent years. All modern browsers support SVG, and it would seem that the Web should already switch to vector graphics. However, there are some restrictions on the use of SVG, and sometimes you need to convert SVG.

3. What other file formats can I convert SVG to?

Aspose.SVG API provides a wide range of SVG conversions to popular formats, such as PDF, XPS, DOCX, JPEG, PNG, BMP, TIFF, and GIF.

4. Can I convert SVG to PNG on Linux, Mac OS, Android or iOS?

Yes, you can use SVG Converter on any operating system that has a web browser. It works online and does not require any software installation.

Get Started with Aspose.SVG for .NET API

If you are interested in developing scalable vector graphics and their application, install our flexible, high-speed Aspose.SVG for .NET API with a powerful set of interfaces for C# and other .NET programming languages.
Install from command line as nuget install Aspose.SVG or via Package Manager Console of Visual Studio with Install-Package Aspose.SVG. Alternatively, get the offline MSI installer or DLLs in a ZIP file from downloads. Aspose.SVG for .NET API is a standalone library and does not depend on any software for SVG document processing.
For more details about C# library installation and system requirements, please refer to Aspose.SVG Documentation.

Other Supported SVG Conversions

You can also convert SVG to many other file formats:

SVG TO PDF (Portable Document Format)
SVG TO BMP (Bitmap Image)
SVG TO IMAGE (Image formats)
SVG TO JPEG (JPEG Image)
SVG TO GIF (Graphical Interchange Format)
SVG TO PNG (Portable Network Graphics)