views:

1701

answers:

4

Hello,

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.

+8  A: 

Check this out.

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.

SDX2000
+1 for your superior Google-fu.
MusiGenesis
+1, My google-fu didn't find this one.
liori
MusiGenesis and liori...thanks :)
SDX2000
This seems to be the main project page: http://www.jbrowse.com/svgnet/. It looks like the library has not been developed for 6 years. I'll probably still check it.
liori
+1  A: 

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.

Audrius
The problem is time: we'd like to spend as little time as possible on this task, and SVG support is not really vital for us. Therefore we're looking for something that could possibly be used as in-place replacement for GDI API... or at least something that would not need much adaptation. Your suggestion was also already considered by us.
liori
I see. Then SDX2000 suggestion is the most logical approach to this (-.
Audrius
Ok I'll just put in for a one year sabbatical so I can implement that.
Martin Murphy
+2  A: 

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

jdehaan