Convert SVG to JPG PNG Image C#

SVG (Scalable Vector Graphics) is a widely used format for vector-based graphics. While SVG offers scalability and high-quality rendering, you may often need to convert SVG files to raster image formats like JPG or PNG for broader compatibility, such as embedding in reports, web pages, or mobile applications. In this blog post, we’ll walk you through the steps to convert SVG to JPG and PNG in C#.

SVG to Image Converter - C# API Installation

To convert SVG to raster image format, you need to install Conholdate.Total for .NET from the New Releases or run the following NuGet installation command:

PM> NuGet\Install-Package Conholdate.Total

Why Convert SVG to Image Formats?

There are several reasons why developers and designers need to convert SVG files to raster image formats like JPG and PNG:

  • Compatibility: Many applications and platforms do not support SVG, but they readily support JPG or PNG.
  • Performance: Raster images render faster on certain platforms and consume less processing power compared to rendering SVG dynamically.
  • Printing: SVG may lose details or fail to render correctly in print formats, whereas PNG and JPG provide print-ready quality.
  • Integration: Raster images are often easier to embed into documents, emails, and multimedia presentations.

Now, let’s dive into the implementation.

Convert SVG to JPG in C#

You can convert SVG to JPG format in C# with the following steps:

  • Load any input SVG or define the SVG code.
  • Specify the path where the JPG file will be saved.
  • Use ImageSaveOptions to set the output format as JPEG.
  • Call ConvertSVG to process the conversion.

The following sample shows how to convert SVG to JPG in C#:

Convert SVG to PNG Image in C#

For converting SVG to PNG, the process is similar but requires changing the output format to PNG:

  • Read the source SVG or create any SVG image.
  • Provide the file path to write the PNG file.
  • Create an instance of the ImageSaveOptions class and specify PNG as the desired format.
  • Convert SVG to PNG with the ConvertSVG method.

The code snippet below demonstrates to convert SVG to PNG in C#:

Free Evaluation License

You can request a free temporary license to test the API to its full capacity.

Summing Up

Converting SVG to raster image formats like JPG and PNG is a common requirement in various applications. Whether you need high-quality images for web applications, reports, or multimedia projects, the provided code snippets ensure reliable SVG to image conversion. In case of any concerns, please write to us at the forum.

See Also