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.
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
There's no easy way, although SVG paths and GraphicsPath
look similar and serve the same purpose, there are some differences in how things are specified and handled. One example: SVG arc definition is different from how GraphicsPath
defines arcs, so you'll need to do a little bit of trigonometry to convert it.
Also check out Drawing SVG in .NET/C#?
I hope this ain't late! Check out the source code of the svg viewer program from AGG: http://www.antigrain.com/svg/index.html
The source code is in C++ and uses the AGG graphics engine, but it's easy to translate to GDI+. It also handles the conversion of SVG Arc to a Bezier Arc which can then be used with GDI+.
Good luck
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With