Drawing SVG in .NET/C#?

C#SvgVector Graphics

C# Problem Overview


I'd like to generate an SVG file using C#. I already have code to draw them in PNG and EMF formats (using framework's standard class System.Drawing.Imaging.Metafile and ZedGraph). What could you recommend to do to adapt that code to SVG? Preferably I'd like to find some library (free or not) that would mimic System.Drawing.Graphics interface.

C# Solutions


Solution 1 - C#

Check out the SVG framework in C# and an SVG-GDI+ bridge project.

From the above web page...

> The SvgGdi bridge is a set of classes > that use SvgNet to translate between > SVG and GDI+. What this means is that > any code that uses GDI+ to draw > graphics can easily output SVG as > well, simply by plugging in the > SvgGraphics object. This object is > exactly the same as a regular .NET > Graphics object, but creates an SVG > tree. Even things like hatched fills > and line anchors are implemented.

Solution 2 - C#

We have made a public fork of the C# .NET SVG library on Github.

It is much improved over the one you find on Codeplex, please have a look and fork it as you like:

https://github.com/svg-net/SVG

Edit: Just to let you know, as of January 2021:

While others seem dead for years, this is still active. But we could definitely use some help from other developers.

Solution 3 - C#

I used this one http://svg.codeplex.com/ and I am quite satisfied with it. Still has some bugs so you should have a look at the patches in http://svg.codeplex.com/SourceControl/PatchList.aspx.

When I discover mistakes I can solve I post them directly there. But it takes some time to be evaluated by the guys there. It's a better idea to have a look at the patches and apply them yourself.

The library is reasonably sufficient for most usual needs. for really fancy stuff, it needs to be improved thought...

Solution 4 - C#

As SVG is basically a XML document - you can implement "drawing" yourself. Check the specs at W3C SVG spec. I did it once to generate SVG signature images, all it took was a couple of hours and a firefox to test the generated image.

Of course this applies if you are generating image from user input or if you do not mind spending some time doing conversion from another vector image format.

P.S. you can create your own wrapper to mimic System.Drawing.Graphics, e.g. DrawLine() to append to the internal buffer and so on.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionlioriView Question on Stackoverflow
Solution 1 - C#AutodidactView Answer on Stackoverflow
Solution 2 - C#thalmView Answer on Stackoverflow
Solution 3 - C#jdehaanView Answer on Stackoverflow
Solution 4 - C#AudriusView Answer on Stackoverflow