SVG to JPEG 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 JPEG programmatically with full control over a wide range of conversion parameters. Powerful C# API allows you to convert SVG to popular formats with high speed and high quality. Convert SVG files to JPEG, making it easy to share, collaborate, and present visual content across devices and platforms!
Free Online Converter
Test the quality of SVG to JPEG 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 JPEG 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.
using Aspose.Svg; using Aspose.Svg.Saving; using Aspose.Svg.Converters; using Aspose.Svg.Rendering.Image; using var document = new SVGDocument("{{input lower}}"); {{#if_output 'PDF'}} var options = new PdfSaveOptions(); {{/if_output}} {{#if_output 'XPS'}} var options = new XpsSaveOptions(); {{/if_output}} {{#if_output 'BMP' 'JPG' 'GIF' 'PNG' 'TIFF'}} var options = new ImageSaveOptions(ImageFormat.{{output param2 camel}}); {{/if_output}} Converter.ConvertSVG(document, options, "output.{{output lower}}");
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 JPEG using ConvertSVG() Method
- Load an SVG file using one of the SVGDocument() constructors of the SVGDocument class.
- Create a new
ImageSaveOptions
object with JPEG ImageFormat. By default, the
Format
property is PNG. - Use the ConvertSVG() method to save SVG as a JPEG image. You need to pass the SVGDocument, ImageSaveOptions, and output file path to the ConvertSVG() method.
- The JPEG file will be saved to the specified path.
Steps to Convert SVG to JPEG using RenderTo() Method
- Initialize SVGDocument with your SVG file.
- Create an object of the ImageRenderingOptions class. Use the
ImageRenderingOptions()
constructor and specify the
Format
property of the document. - Initialize ImageDevice class and specify the output file name to render.
- Call RenderTo() method & pass the instance of the ImageDevice.
Convert SVG to JPEG
using (var document = new SVGDocument("input.svg"))
{
var options = new ImageRenderingOptions(ImageFormat.Jpeg);
using (IDevice device = new ImageDevice(options, "output.jpg"))
{
document.RenderTo(device);
}
}
FAQ
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 JPEG programmatically.
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.
Aspose.SVG API provides a wide range of SVG conversions to popular formats, such as PDF, XPS, DOCX, JPEG, PNG, BMP, TIFF, and GIF.
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: