Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
To convert an image to SVG in C#, create an ImageVectorizerConfiguration object and call Converter.ConvertImageToSVG(). Aspose.SVG for .NET supports raster inputs such as PNG, JPG, BMP, TIFF, GIF, and ICO and saves the traced vector result as an SVG file.
Vectorization is the process of converting raster images into vector graphics, which use Bezier curves, splines, and lines instead of pixels. The process includes color quantization, boundary detection, shape approximation, and path-quality improvements such as smoothing or simplification. The result is saved as a vector format, such as SVG.
Aspose.SVG for .NET provides two image vectorization workflows: the
Converter.ConvertImageToSVG() facade for direct image-to-file conversion, and the
ImageVectorization API when your code needs to work with the generated SVGDocument.
This article focuses on direct image-to-SVG conversion with Converter.ConvertImageToSVG(). For the full algorithm workflow and ImageVectorizer.Vectorize() examples, see
Image and Text Vectorization and
Image Vectorization Workflow.
Image vectorization works best when the source image contains clear shapes, limited colors, and visible boundaries. It is less suitable for full-color photos where preserving every detail would create a very complex SVG.
| Source image type | Recommendation |
|---|---|
| Logos, icons, symbols, clip art | Good fit for image to SVG conversion. These images usually contain clean shapes and limited colors. |
| Diagrams, maps, line art, technical drawings | Good fit when lines and regions are clear enough to trace. |
| Scanned drawings | Useful after preprocessing, such as cleaning noise and improving contrast. |
| Photographs | Usually not ideal for compact SVG. Vectorization may produce many paths and a large output file. |
| Low-resolution or noisy images | Improve the source image first, or adjust smoothing and simplification options. |
Use Converter.ConvertImageToSVG() when you want to convert an image file or stream directly to an SVG file. Use ImageVectorizer.Vectorize() when your code needs the vectorized result as an SVGDocument before saving, editing, or inspecting it. This article focuses on the direct conversion workflow.
The following example demonstrates how to convert a raster PNG image to SVG using the ConvertImageToSVG() method:
configuration, imageFile, outputFile) method vectorizes the input image, converting it into a scalable SVG format and saving it to the specified output path.Add the following namespaces:
1using Aspose.Svg;
2using System.IO;
3using Aspose.Svg.Converters;
4using Aspose.Svg.ImageVectorization;C# code for image to SVG conversion:
1// Convert a raster image to SVG in C# using ConvertImageToSVG()
2
3// Prepare paths for a source image file and output SVG file
4string imageFile = Path.Combine(DataDir, "flower-pink.png");
5string outputFile = Path.Combine(OutputDir, "flower-pink.svg");
6
7// Create a configuration object
8ImageVectorizerConfiguration configuration = new ImageVectorizerConfiguration
9{
10 PathBuilder =
11 new BezierPathBuilder
12 {
13 TraceSmoother = new ImageTraceSmoother(3),
14 ErrorThreshold = 5,
15 MaxIterations = 5
16 },
17 ColorsLimit = 15,
18 LineWidth = 2
19};
20
21// Convert Image to SVG
22Converter.ConvertImageToSVG(configuration, imageFile, outputFile);The figure shows the result of image vectorization: a) original PNG image; b) resulting SVG:

Use ImageVectorizerConfiguration and path builder settings to balance visual detail, path smoothness, file size, and processing time.
| Goal | Option to review | Result |
|---|---|---|
| Reduce SVG file size | ColorsLimit, trace simplification | Fewer colors and fewer path points. |
| Control traced line thickness | LineWidth | Thicker or thinner generated vector strokes. |
| Smooth jagged edges | TraceSmoother in
BezierPathBuilder | Cleaner curves for noisy or low-resolution images. |
| Preserve more detail | ErrorThreshold, MaxIterations | More accurate paths, but potentially larger SVG output. |
| Create a stencil-like result | Stencil configuration | Simplified, high-contrast vector output. |
Aspose.SVG for .NET supports both file-based and stream-based workflows, making it flexible for desktop, web, and service-oriented applications. The following example shows how to apply the
ConvertImageToSVG(configuration, inputStream, outputFile) method for JPG to SVG conversion:
1// Convert a raster JPG stream to vector SVG in C#
2
3// Prepare input and output
4string imagePath = Path.Combine(DataDir, "tulip.jpg");
5string outputFile = Path.Combine(OutputDir, "tulip.svg");
6
7// Open the image as a FileStream
8using (FileStream inputStream = new FileStream(imagePath, FileMode.Open, FileAccess.Read))
9{
10 // Create vectorization configuration
11 ImageVectorizerConfiguration configuration = new ImageVectorizerConfiguration
12 {
13 PathBuilder = new BezierPathBuilder
14 {
15 TraceSmoother = new ImageTraceSmoother(1),
16 ErrorThreshold = 10,
17 MaxIterations = 1
18 },
19 ColorsLimit = 30,
20 LineWidth = 1
21 };
22
23 // Perform conversion from image stream to SVG
24 Converter.ConvertImageToSVG(configuration, inputStream, outputFile);
25}
26
27Console.WriteLine("Image converted to SVG successfully.");The figure shows the result of image vectorization: a) original JPG image; b) resulting SVG:

| Problem | Common cause | Fix |
|---|---|---|
| Output SVG is very large | The source image has too many colors, noise, or photographic detail | Use simpler source artwork, reduce ColorsLimit, resize the image, or apply trace simplification. |
| Vector edges look rough | The source image is low-resolution or noisy | Clean the image before conversion and increase smoothing with TraceSmoother. |
| Colors are too simplified | Color quantization is too aggressive | Increase ColorsLimit or use a cleaner source image with clearer color regions. |
| Text in the image is not editable SVG text | Image vectorization traces pixels into shapes | Use real SVG text when editable text is required. See SVG Text and Text Vectorization. |
Can I convert PNG to SVG in C#?
Yes. Use Converter.ConvertImageToSVG() for direct PNG to SVG conversion. For a PNG-focused workflow with ImageVectorizer, see
Convert PNG to SVG in C#.
Can I convert an uploaded image stream to SVG?
Yes. Use the stream-based ConvertImageToSVG(configuration, inputStream, outputFile) overload when the input image comes from an upload, memory buffer, or cloud storage.
Should I vectorize photos to SVG?
Usually only when you intentionally want a stylized vector effect. Photos often create large SVG files with many paths, so ordinary raster formats are usually better for photographic content.
Does image to SVG conversion create editable text?
No. Raster image vectorization traces visible pixels into vector shapes. Text inside a source image does not become editable SVG <text> content.
How do I make the generated SVG smaller?
Use a cleaner source image, reduce the number of colors with ColorsLimit, resize very large inputs, and use simplification settings to reduce path complexity.
ImageVectorizer.Aspose.SVG offers a Free Online Image to SVG Converter that works on any platform and provides accurate and efficient conversion. Using this application, you can apply a set of options to achieve the perfect result. Save your time and check this free Image to SVG Converter to get all the benefits of vector graphics!
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.