преобразование svg в изображение программно

Я пытаюсь преобразовать мой svg в изображение Я изучил несколько инструментов и все еще не могу сделать это :(

1. SVG rendering engine но у меня с ним проблемы, так как нет документации

вот мой код:

 using (FileStream fileStream = File.OpenRead(@"C:\sample.svg"))
        {
            MemoryStream memoryStream = new MemoryStream();
            memoryStream.SetLength(fileStream.Length);
            fileStream.Read(memoryStream.GetBuffer(), 0, (int)fileStream.Length);
            SvgDocument svgDocument = SvgDocument.Open(memoryStream);
            string imagePath = "local.jpg";
            svgDocument.Draw().Save(imagePath);
        }

или вот:

        var sampleDoc = SvgDocument.Open(@"C:\sample.svg");
        sampleDoc.Draw().Save(@"C:\sample.png");

ни то, ни другое не работает!

Я получаю ошибку:

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error: 


Line 363:                SvgDocument svgDocument = SvgDocument.Open(memoryStream);
Line 364:                string imagePath = "local.jpg";
Line 365:                svgDocument.Draw().Save(imagePath);
Line 366:            }
Line 367:  

Проблема в том, что svgDocument is null!


2. Inkscape

мой код:

 string svgFileName = HttpContext.Current.Server.MapPath("sample.svg");
        string PngRelativeDirectory = HttpContext.Current.Server.MapPath("~/");
        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);
        context.Response.Redirect(PngRelativeDirectory + pngName); 

но ничего не происходит!!! я думаю мне не хватает чего-то для сохранения изображения вместо RewritePath()


если у вас есть лучшее решение для меня, выложите его с примером как его использовать, спасибо

вот мой svg:





JanuaryFebruaryMarchAprilMayJuneJanuaryFebruaryMarchAprilMayJune


6
задан Cœur 3 January 2019 в 05:40
поделиться