Vectorize Image in C#

Vectorizing an image is the process to convert raster images, made up of pixels, into vector graphics, made up of paths and shapes. The output is a scalable image that can be resized without losing the image quality. Accordingly, this article explains how to vectorize images in C#.

C# API to Vectorize Image - Installation

Aspose.SVG for .NET can be used to convert an image to vector graphics. It is useful in various scenarios, such as when you want to print a logo on a billboard or resize an image for a responsive website. You need to configure the DLL file or run the NuGet installation command below:

PM> Install-Package Aspose.SVG

How to Vectorize Image in C#

You can vectorize an image by following the steps below:

  1. Initiate an instance of ImageVectorizer class.
  2. Set the configuration with different properties.
  3. Vectorize the raster image.
  4. Export the output vector image.

The subsequent section further demonstrates how to vectorize images in C#:

Convert Image to Vector in C#

You need to follow the steps below to vectorize images in C#:

  1. Initialize an object of ImageVectorizer class.
  2. Configure different properties like Trace Smoother, Trace Simplifier, etc.
  3. Vectorize the raster image with the method call.
  4. Export the output Vector image to SVG format.

The following code sample shows how to vectorize images in C#:

// Initialize an instance of the ImageVectorizer class
var vectorizer = new Aspose.Svg.ImageVectorization.ImageVectorizer
{
    Configuration =
    {
        TraceSmoother =   new Aspose.Svg.ImageVectorization.ImageTraceSmoother(1),
        TraceSimplifier = new Aspose.Svg.ImageVectorization.ImageTraceSimplifier(0.5f),
        ColorsLimit = 3
    }
};

// Vectorize raster image from the specified file
using var document = vectorizer.Vectorize(Path.Combine(dataDir, "owl.png"));

// Save vectorized image as SVG file 
document.Save(Path.Combine(dataDir, "olw.svg"));

Get a Free API License

You can get a free temporary license to test the API without any evaluation limitations.

Conclusion

In this article, you have learned how to vectorize images in C#. It converts the raster image in JPG, PNG, etc. format to Vector format SVG file. In case of any ambiguities, please write to us at the free support forum.

See Also