liori
liori

Reputation: 42367

Drawing SVG in .NET/C#?

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.

Upvotes: 72

Views: 108284

Answers (4)

thalm
thalm

Reputation: 2930

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 February 2024:

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

Upvotes: 39

Sandeep Datta
Sandeep Datta

Reputation: 29345

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.

Upvotes: 42

jdehaan
jdehaan

Reputation: 19938

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...

Upvotes: 8

Audrius
Audrius

Reputation: 2838

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.

Upvotes: 4

Related Questions