Image Vectorization – C# code and Online Vectorizer

Are you ready to move on to vector drawing?

What is Image Vectorization?

Image vectorization is the process of converting bitmap images into vector graphics – Bezier curves, splines, and lines. Vectorization is helpful because the image will not pixelate when you enlarge it. Scaling without losing quality, small file size, and animation support – are only a few advantages of vectorized images. Whether you are into painting, design, art, printing, architecture or web development, vector images are an essential part of the profession. On the other hand, you just can experiment with images and get some fun vectorizing effects. In this article, we’ll look at how to convert Image to vector graphics in C# or using an online Image Vectorizer.


Online Image Vectorizer

Are you ready to go from painting with pixels to drawing with vectors? Image Vectorizer is designed to convert raster images into vector graphics based on geometric shapes consisting of Bezier curves and lines. All vector graphics elements are saved to SVG files after vectorization. Image Vectorizer supports JPEG, JPG, PJP, PJPEG, PNG, BMP, ICO, GIF, TIFF, WEBP, XBM and other bitmap formats. You are able to interactively manage the vectorized SVG file by using controls linked with proper vectorization options. Convert your images into scalable and clear vector art just now!


How to use Image Vectorizer?

  1. First, load the raster image from a local file system in JPEG, JPG, PJP, PJPEG, WEBP, PNG, BMP, ICO, GIF, TIFF, XBM or other bitmap format. You will see three windows - Source Image, Quantized Image and Vectorized Image - with the preview of initial, color-quantized and vectorized images.
  2. Image Vectorizer converts Image to vector with default settings and you can download vectorized Image as an SVG file. But for getting a better result, you can handle the quantization and vectorization processes with two settings sidebars. Click “Quantize” button to apply quantization settings, click “Vectorize” button to apply vectorization settings and convert Image to SVG.
  3. Click the “Download” button to get the resultant.

Image Vectorizer converts raster bitmap images into vector artwork constructed from outlines. The vectorization algorithm includes the next steps: color quantization, contour tracing, trace smoothing, trace simplification, and building SVG path elements from the traces. Apply custom settings to get the best Image vectorization result.

Quantization Options

Color quantization is a process of selecting the limited number of colors to use in an image. It is applied when the color information of an image is to be reduced. Color quantization is a very complex process involving a number of factors. This can be implemented using different algorithms. Each of the algorithms determines which colors from the larger set of colors remain in the new image and how the discarded colors are mapped to the remaining ones.

  • colors - desired palette size;
  • method - histogram methods that implement various color quantization algorithms;
  • minHueCols - is a parameter that works with color gradients;
  • scale - or scaling factor - configurable for finer or coarser sampling of colors;
  • grayscale - you can convert the image to grayscale by clicking the checkbox.

Vectorization Options

  • threshold - is responsible for setting the number of pixels to mark the contour;
  • severity - affects contours’ smoothing and determines the extent of the region considered by query point the Nearest Neighbor approach;
  • line-width - affects lines’ width for marking the contours;
  • stencil - turns an ordinary image or photo into an outline image that can be used as a stencil for graffiti-like effects;
  • trace paths - you can view the points in a curve that are responsible for building path segments.

Vector graphics are the best for creating logos, icons, page layouts, maps, graphs, line arts, illustrations, technical drawings and more. It is not the most suitable format for continuous-tone images with blends of color or editing photographs. However, vectorizing photos can result in impressive artistic effects that can be interesting and useful.

How to Vectorize Image in C#

Aspose.SVG for .NET API offers a high-speed C# library that you can use for different SVG parsing tasks. The ImageVectorization Namespace includes classes and interfaces for implementing the image vectorization process and work with various pre-processing options for images before saving them in vector format. Processing involves controlling the following vectorization options: TraceSimplifier, TraceSmoother, PathBuilder, etc.


Image Vectorization in C#

	// Initialize an instance of the ImageVectorizer class
	var vectorizer = new ImageVectorizer
    {
		//optionally set configuration
        Configuration =
        {
			//optionally set path builder
            PathBuilder = new BezierPathBuilder {
			//optionally set trace smoother
            TraceSmoother = new ImageTraceSmoother(1),
                ErrorThreshold =  30,
                MaxIterations = 30
            },
            ColorsLimit = 25,
            LineWidth = 1
        }
    };
    // Vectorize image from the specified file
	using var document = vectorizer.Vectorize(InputFolder + "image.png");
    // Save vectorized Image as SVG file 
	document.Save(OutputFolder + "image.svg");

Steps to Vectorize Image in C#

  1. Initialize an instance of the ImageVectorizer class. Use one of ImageVectorizer() constructors and specify configuration properties.
    • TraceSmoother property sets the trace smoother. It is used to smooth out fragments of contours.
    • TraceSimplifier property sets the trace simplified. As a result, the trace curve will be built composed of line segments with fewer (or bigger) points.
    • PathBuilder property sets the SVG path segments builder and affects how sharply the curve bends at the control points.
  2. Vectorize Image from the specified file. The Vectorize() method takes the path to the image file and returns an SVGDocument.
  3. Save the vectorized Image as an SVG file. Use the Save() method and pass to it the output path.

Image Vectorization in Documentation

Scalable Vector Graphics is currently widely used for rendering web graphics. Compared to bitmaps, vector graphics can create sharp images that scale to any size, they are ideal for drawing any kind of web illustration, including icons, charts, diagrams, and more. In the documentation chapter Vectorization – Basic Overview, you will find a description of the image vectorization process.

  • Image Vectorization Workflow – You will find image vectorization info, a description of the image vectorization process and vectorization options, learn how to vectorize raster images such as PNG, JPG, BMP, TIFF, GIF, ICO into an SVG document.
  • Image Vectorization Examples – You will consider a few C# examples that demonstrate the ImageVectorization functionalities and the effect of configuration properties on the vectorization result.

FAQ

1. How can I vectorize Image?

Aspose.SVG allows you to convert Image to SVG in any way – online or programmatically. For example, you can vectorize Image in real-time using Online Image Vectorizer that converts your images quickly and with high quality. On other hand, you can use Aspose.SVG to vectorize Image programmatically.

2. What is a raster to vector conversion?

The process of image conversion from raster to vector is called image vectorization. It is a complex computational process that converts a bitmap image made up of pixels into a vector image made up of lines, curves, and other geometric shapes.

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 Vectorizers

Save your time and check these Image Vectorizers to get all the benefits of vector graphics!

Text to Vector (SVG Text)
Stencil Drawing (Stencil images)
JPG to SVG (JPEG Image)
PNG to SVG (Portable Network Graphics)
Image to SVG (Raster Image)
BMP to SVG (Microsoft Windows Bitmap)
GIF to SVG (Graphical Interchange Format)
TIFF to SVG (Tagged Image File Format)
ICO to SVG (Windows Icon)