Convert Raster to SVG | SVG to Raster Image Conversion

Convert Raster to SVG | SVG to Raster Image Conversion

Welcome to this new blog post. You are landed in the right place if you are looking to automate the SVG to raster image conversion programmatically. We will install this .NET imaging library in our .NET application to access the methods. In addition, we will write the steps and the code snippet to convert raster to SVG programmatically. However, building a raster to SVG or SVG to raster converter will surely give you a competitive edge in your business software.

We will cover the following sections:

.NET imaging library installation

This library is rich-featured and offers a wide range of enterprise-level features that help developers to develop resource-efficient applications. However, you can either install it within your .NET application by running the following command in the NuGet Package Manager or download API’s DLL.

Install-Package Aspose.Imaging

Convert raster to SVG in C#

You may follow the following code snippet and the steps to convert raster image to SVG programmatically :

  1. Create an object of the Image class and invoke the load method to load a specific image.
  2. Instantiate an instance of the SvgOptions class to access the SVG file format creation options.
  3. Create an instance of the SvgRasterizationOptions class to access the SVG rasterization options.
  4. Assign the svgRasterizationOptions to the VectorRasterizationOptions property.
  5. Set the page width of the SVG by setting the value of the PageWidth property.
  6. Set the height by setting the value of the PageHeight property.
  7. Save the file in SVG format by invoking the Save method.

Copy & paste the following code into your main file:

You may see the output in the image below:

ratser to SVG converter

SVG to raster image conversion

In addition, you can build an SVG to raster converter using this .NET imaging library.

Following are the steps:

  1. Load the image by creating an object of the SvgImage class and invoke the load method to load a specific SVG file.
  2. Create an instance of the PngOptions class.
  3. Initialize an instance of the SvgRasterizationOptions class to access the SVG rasterization options.
  4. Set the page width by setting the value of the PageWidth property.
  5. Set the page height by setting the value of the PageHeight property.
  6. Assign the svgOptions to the VectorRasterizationOptions property.
  7. Invoke the Save method to save the raster image.

Copy & paste the following code into your main file:

You may see the output in the image below:

SVG to raster image conversion

Get a Free License

You can avail a free temporary license to try the API without evaluation limitations.

Summing up

Likewise, you may visit the documentation to know the other features and popular conversions. Therefore, you have learned how to convert raster to SVG using .NET imaging library. Moreover, you also have gone through how to implement SVG to raster Image conversion in a C# application. There are some relevant articles enlisted in the See Also section below that might help you further.

Moreover, we suggest you follow our Getting Started guide.

Finally, conholdate.com is writing new blog posts. Therefore, please stay in touch for regular updates.

Ask a question

You can let us know about your questions or queries on our forum.

FAQs

How do I convert images to SVG?

Please follow this link to know the code snippet that converts raster images to SVG and SVG to raster images programmatically.

See Also