SVG Converter – C# code and Online Converter
Convert SVG Using C#
SVG files are Scalable Vector Graphics Files that use XML based text format for describing the appearance of an image. The word Scalable refers to the fact that SVG can be scaled to different sizes without losing any quality. A text-based description of such files makes them independent of resolution. It is one of the most used formats for website building and print graphics to achieve scalability.
The main highlight of Aspose.HTML is the conversion feature. Converting between formats is required for various reasons: to work in a familiar, convenient format or to take advantage of different formats for specific tasks. The Aspose.Html.Converters namespace implements easy access to conversion methods. It provides a wide range of SVG conversions to popular formats, such as PDF, XPS, DOCX, JPG, PNG, BMP, TIFF, and GIF.
The articles in this section provide information on the list of supported SVG conversions and how to perform them using ConvertSVG() methods. It can be different scenarios, but any SVG conversion can be made with a few required steps:
- Load an SVG document. You can load SVG from a file, SVG code, stream, or URL.
- Create a Save Options object. You may customize the rendering process to get the desired result.
- Invoke one of the ConvertSVG() methods and pass the required parameters to it.
Please take a look over the following C# code snippet, which shows the process of converting SVG to PNG with ImageSaveOptions specifying:
1// Prepare a path to a source SVG file
2string documentPath = Path.Combine(DataDir, "flower1.svg");
3
4// Prepare a path to save the converted file
5string savePath = Path.Combine(OutputDir, "flower-options.png");
6
7// Initialize an SVG document from the file
8using var document = new SVGDocument(documentPath);
9
10// Create an instance of the ImageSaveOptions class. Set up the SmoothingMode, resolutions, and change the background color to AliceBlue
11var options = new ImageSaveOptions()
12{
13 HorizontalResolution = 200,
14 VerticalResolution = 200,
15 BackgroundColor = System.Drawing.Color.AliceBlue,
16 UseAntialiasing = true,
17};
18
19// Convert SVG to PNG
20Converter.ConvertSVG(document, options, savePath);
In the example, the
SVGDocument(address
) constructor initializes an SVG document from the file. The ImageSaveOptions() constructor creates a new
ImageSaveOptions object with PNG ImageFormat, BackgroundColor and other properties. Then, the
ConvertSVG() method takes SVGDocument, ImageSaveOptions, and output path and performs SVG to PNG conversion.
Online SVG Converter
You can convert SVG to other formats with Aspose.HTML API in real time. First, load an SVG file from your local drive and then run the example. The save options in the example are set by default. You will immediately receive the conversion result as a separate file.
Aspose.HTML offers free online SVG Converters for converting SVG files to a variety of popular formats. You can easily convert SVG to PDF, SVG to XPS, SVG to JPG, SVG to PNG, SVG to BMP, SVG to TIFF, or SVG to GIF. Just select the file, choose the format to convert, and you’re done. It’s fast and completely free!