Converting SVG path data into GDI+ GraphicsPath data

Icemanind picture Icemanind · Apr 19, 2011 · Viewed 9.1k times · Source

Is there an easy way to convert an SVG path tag into a C# System.Drawing.Drawing2D.GraphicsPath? They are both closely related and I was hoping there would be an easy to convert the SVG path data into GraphicsPath Points.

Answer

Drew Noakes picture Drew Noakes · Aug 15, 2013

This SVG project provides a solution in the following way:

var pathData = ...;

var graphicsPath = new GraphicsPath();

foreach (var segment in SvgPathBuilder.Parse(pathData))
    segment.AddToPath(graphicsPath);

graphics.DrawPath(Pens.Black, graphicsPath);

It's available as a NuGet package via:

PM> Install-Package Svg