Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting SVG to PNG using C# [closed]

Tags:

c#

.net

png

svg

I've been trying to convert SVG images to PNG using C#, without having to write too much code. Can anyone recommend a library or example code for doing this?

like image 724
harriyott Avatar asked Sep 12 '08 13:09

harriyott


People also ask

How do I convert an SVG to PNG?

Navigate to an . svg file, right click on it and click on the context menu item 'Save SVG as PNG. Lets you click on the extension icon or right click on an . svg file and choose Save SVG as PNG.

How do I convert SVG to JPEG?

Go to File. Select Export. Click Export As. Select JPG format from the drop-down menu.

How do I convert a SVG file?

How to convert a SVG to a PNG file? Choose the SVG file that you want to convert. Select PNG as the the format you want to convert your SVG file to. Click "Convert" to convert your SVG file.


2 Answers

There is a much easier way using the library http://svg.codeplex.com/ (Newer version @GIT, @NuGet). Here is my code

var byteArray = Encoding.ASCII.GetBytes(svgFileContents); using (var stream = new MemoryStream(byteArray)) {     var svgDocument = SvgDocument.Open(stream);     var bitmap = svgDocument.Draw();     bitmap.Save(path, ImageFormat.Png); } 
like image 175
Anish Avatar answered Oct 26 '22 06:10

Anish


You can call the command-line version of inkscape to do this:

http://harriyott.com/2008/05/converting-svg-images-to-png-in-c.aspx

Also there is a C# SVG rendering engine, primarily designed to allow SVG files to be used on the web on codeplex that might suit your needs if that is your problem:

Original Project
http://www.codeplex.com/svg

Fork with fixes and more activity: (added 7/2013)
https://github.com/vvvv/SVG

like image 23
Espo Avatar answered Oct 26 '22 06:10

Espo