C# .svg file to System.Drawing.Image

I need to convert the selected .svg file to System.Drawing.Image object, so I can resize it and save it as .png. Can anyone help me with this?

Here is what I have so far:

Svg.SvgDocument svgDocument = SVGParser.GetSvgDocument(mPath);
image = svgDocument.Draw();

But it gives me out of memory error.


Solution 1:

You can use the SVG Rendering Engine Lib:

Install-Package Svg

It's quite easy to draw images using it:

var svgDoc = SvgDocument.Open(imagePath);

using(var Image = new Bitmap(svgDoc.Draw()))
{
    Image.Save(context.Response.OutputStream, ImageFormat.Png);
    context.Response.ContentType = "image/png";
    context.Response.Cache.SetCacheability(HttpCacheability.Public);
    context.Response.Cache.SetExpires(DateTime.Now.AddMonths(1));
}

In this example i'm using a handler to display the image on the browser but you can easily save it on some folder just by changing the first parameter of the Save method.