Javascript 使用svg渲染引擎将svg转换为png时出现异常

Javascript 使用svg渲染引擎将svg转换为png时出现异常,javascript,c#,svg,Javascript,C#,Svg,我正在尝试使用c在asp.net应用程序中将svg转换为png。我得到了他的一些帮助。我听从了安妮什的建议。但我在这方面有例外。我不知道这个。我的代码包括: string path = "d:\\"; string svgstr = temp.Value; var byteArray = Encoding.ASCII.GetBytes(svgstr); var stream = new MemoryS

我正在尝试使用c在asp.net应用程序中将svg转换为png。我得到了他的一些帮助。我听从了安妮什的建议。但我在这方面有例外。我不知道这个。我的代码包括:

            string path = "d:\\";
            string svgstr = temp.Value;
            var byteArray = Encoding.ASCII.GetBytes(svgstr);
            var stream = new MemoryStream(byteArray);
            var bitmap = SvgDocument.Open(stream).Draw();
            bitmap.Save(path, ImageFormat.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 102:            var stream = new MemoryStream(byteArray);
Line 103:            
Line 104:            var bitmap = SvgDocument.Open(stream).Draw();
Line 105:             
Line 106:                bitmap.Save(path, ImageFormat.Png);

Source File: e:\HighchartDemo\HighchartDemo\ColumnChart.aspx.cs    Line: 104 

我真的需要帮助。任何其他替代方法也会有所帮助。感谢您在js中所做的一切,highcharts还接受两种数据格式JSON和SVG。您需要将导出highchart js引用添加到应用程序中,并在js中执行

这里有一个概述链接


我必须在回答中添加这一点,因为我需要50个repo进行评论,而且我是堆栈溢出新手。

您收到的异常在转换过程中没有发生,但您会得到一个空指针异常,我假设在您尝试创建流时会发生该异常

var stream = new MemoryStream(byteArray);
变量为null,然后尝试从SvgDocument中绘制一个位图,该位图将获取为null的流


您需要检查MemoryStream为null/byteArray无效的原因

我已经在svg中完成了图表绘制。现在,我只想将其转换为图像进行导出。您可以使用phantom.js创建图像并存储在服务器上,然后您可以从那里导出。。Phantom.js用于在highcharts中的服务器端创建映像。这里有一个链接供参考。