Merge SVG to PNG Using C#

SVG is one of the most used formats for website building and print graphics to achieve scalability. But sometimes, you need to merge SVG files and save them as one document in another file format. PNG refers to a type of raster image file format that uses lossless compression. PNG widely takes to transmit pictures over the network and display photos and graphics on web pages and cloud drive repositories. With Aspose.SVG for .NET API, you can merge SVG to PNG programmatically. Powerful C# API helps you to combine SVG files quickly and in high quality.


C# code example to merge SVG to PNG

A high-speed C# library allows .NET developers to merge SVG files and convert the combined result into other popular formats such as PDF, XPS, JPEG, PNG, BMP, GIF, and TIFF quickly and efficiently. Documents merging can be done with a few lines of code:


Merge SVG to PNG – C#

// Initialize SVG documents from files to merge 
using (SVGDocument document1 = new SVGDocument("document1.svg"))
using (SVGDocument document2 = new SVGDocument("document2.svg"))
using (SVGDocument document3 = new SVGDocument("document3.svg"))
{
    // Create an instance of SvgRenderer
    using SvgRenderer renderer = new Aspose.Svg.Rendering.SvgRenderer();
    // Create an instance of ImageDevice
    using ImageDevice device = new Aspose.Svg.Rendering.Image.ImageDevice("result.png");
    // Merge SVG to PNG
    renderer.Render(device, document1, document2, document3);
}



Steps to Merge SVG to PNG using C#

  1. Load SVG documents using one of the SVGDocument() constructors.
  2. Create a new instance of the SvgRenderer class.
  3. Use the ImageDevice() constructor to initialize a new instance of the ImageDevice class.
  4. Call the Render() method to merge SVGs to PNG image file.
  5. Multiple SVG files will be saved to the PNG image on the specified path.

In the C# example above, the output format is PNG, as indicated by the use of ImageDevice and choosing a .png file extension. If you want to change the output format, you will need to use a different device class that matches the desired format. For example, you can use PdfDevice for PDF format. Additionally, you will need to provide the appropriate file extension in the output file path.


Please visit our Documentation to learn more about using Aspose.SVG API functions. In the documentation article How to Merge SVG Files , you can consider C# examples of how to merge SVG. Experience the power and flexibility of SVG merging by including Aspose.SVG in your C# projects today!


Online Image Merger

Aspose.SVG offers a free online SVG Merger App that combines multiple SVG images into a single file. You can choose a kind of SVG Merger and save the result to one of the following output formats: JPG, PNG or SVG. Our application is multifunctional. You can create image collages, edit and manipulate images before merging. SVG Merger allows you to freely add SVGs, rotate, scale, add backgrounds, filters and move each image until you are happy with the end result of your design.


FAQ

1. How do I merge multiple SVG files into a single PNG using C#?

Aspose.SVG for .NET makes it easy to load multiple SVG documents and render them into a single PNG file using the SvgRenderer class and ImageDevice. This solution works without installing additional software, supports high-quality rendering, and is suitable for server and desktop .NET applications on Windows, macOS, and Linux.

2. In what formats can I save the result of SVG merge via C#?

You can save the SVG merge result in the most common formats such as JPG, PNG, BMP, GIF, TIFF, etc.

3. What is the advantage of Aspose.SVG for .NET over online SVG to PNG converters?

Unlike online services, Aspose.SVG for .NET works completely offline within your code, ensures complete data privacy, has no file size limit, and allows you to integrate conversion into automated processes. Plus, it supports multiple output formats beyond PNG.

4. Where can I find more information about SVG merging?

Please visit our documentation to learn more about using the Aspose.SVG for .NET API to merge SVG. If you have questions about functionality, found issues, or need a new feature, please start a discussion in our free support forum .



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.