title: transform SVG string to Bitmap ideally in memory in C#
body: <p>I am using the code below to transform a SVG string (svgString) to a Bitmap (myBitmap). Ideally, I want to avoid the round-trip to the hard drive. Do you think this is possible (did not find much documentation the SVG nuget package). By the way, I know that I can also write a bmp to the hard drive but I chose png as the background of a bmp is always black for some reason.</p>
  
  <pre><code>using System.Drawing;
  using System.Drawing.Imaging;
  using System.IO;
  using Svg;
  
  namespace Bla
  {
    class Program
    {
      static void Main(string[] args)
      {
        var svgPath = @"d:\test.svg";
        var pngPath = @"d:\test.png";
        var svgString = @"
        &lt;!DOCTYPE html&gt;
        &lt;html&gt;
        &lt;body&gt;
        &lt;svg height='200' width='500'&gt;
          &lt;polyline points='20,20 40,25 60,40 80,120 120,140 200,180' style='fill:none;stroke:black;stroke-width:3' /&gt;
          Sorry, your browser does not support inline SVG.
        &lt;/svg&gt;
        &lt;/body&gt;
        &lt;/html&gt;
        ";
  
        File.WriteAllText(svgPath, svgString);
  
        var svgDocument = SvgDocument.Open(svgPath);  
        svgDocument.ShapeRendering = SvgShapeRendering.Auto;
  
        var bmp = svgDocument.Draw();              
        bmp.Save(pngPath, ImageFormat.Png);
  
        var myBitmap = new Bitmap(pngPath);
      }
    }
  }
  </code></pre>