Svg Tools

Try searching for “svg to png C#”. You’ll get results like “Invoke the inkscape Process” or a in-progress new implementation of a new SVG renderer. The former is not really acceptable, and the later isn’t ready yet. It’s definitely something to keep an eye on, but not a good enough solution for me, yet.

But, there is a perfectly good solution: rsvg. Unfortunately, rsvg is C, and I want a C# solution. Tada! Or you can browse the source code. Or check it out with svn co Keep reading for more details…

I’m not all that into documentation, so here’s some usage information:

using (SvgImage image = SvgImage.FromData(text))
// Get a System.Drawing.Image
System.Drawing.Image i = image.CreateImage())
// Save this directly to the disk
// Get a System.Drawing.Image at 256×256
Image i2 = image.CreateImage(256, 256);
// Save to a file with a specific size (256×256)
image.Save(“whatever2.png”, 256, 256);

It uses a bunch of open source libraries (jpeg62, libcairo-2, libcroco-0.6-3, libgdk_pixbuf-2.0-0, libgsf-1-114, libpng12-0, librsvg-2-2 and libxml2.dll).

My test data is from W3C Schools SVG Examples and are not my property.

There’s not a lot of code there, but I thought it might be useful. I hope someone else will be able to use the code. All of the code I didn’t write has its own license, but anything I have I consider public domain… although it’d be awesome if you’d just post here so I know whether I should bother updating it with fixes and what not.

Digg this     Create a Bookmark     Add to Newsvine

No Responses to “Svg Tools”

No comments yet

Leave a Reply