convert svg to image programmatically

后端 未结 2 1267
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-29 15:48

I\'m trying to convert my svg to an image I\'ve been looking into several tools and still can\'t make this happen :(

1. SVG rendering engine but I\'

2条回答
  •  滥情空心
    2020-12-29 16:23

    I made a couple of changes to you code here: I think InkScape was having a problem with you paths, you'd used

    PngRelativeDirectory + "\" + pngFileName

    PngRelativeDirectory already had a "\" in it so the path was coming our as c:\\sample.png

    Also i changed the Context.RewritePath to Response.Redirect - I get the pie chart rendered in the browser the browser.

    string svgFileName = HttpContext.Current.Server.MapPath("sample.svg");
    string PngRelativeDirectory = "C:\\";
    string pngName = "svgpieresult.png";
    string pngFileName = HttpContext.Current.Server.MapPath(pngName);
    
    
    /* ignored assume sample.svg is in the web app directory
    using (StreamWriter writer = new StreamWriter(svgFileName, false))
    {
        writer.Write(svgXml);
    }
     */
    
    string inkscapeArgs = string.Format(@"-f ""{0}"" -e ""{1}""", svgFileName, pngFileName);
    
    Process inkscape = Process.Start(
      new ProcessStartInfo( "C:\\Program Files\\inkscape\\inkscape.exe", inkscapeArgs));
    
    inkscape.WaitForExit(3000);
    //Context.RewritePath(pngName);
    this.Response.Redirect(pngName);
    

提交回复
热议问题