繁体   English   中英

使用SVG渲染引擎将svg转换为png时发生异常

[英]Exception when converting svg to png using SVG Rendering Engine

我正在尝试使用C#在我的asp.net应用程序中将svg转换为png n。 我从这里得到了一些帮助。 我听了艾尼斯的建议。 但是我对此感到异常。 我对此一无所知。 我的代码包括:

            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中进行。

这是概述链接http://www.highcharts.com/docs/export-module/export-module-overview

我必须在答案中添加此内容,因为我需要50个repo进行评论,而且我是堆栈溢出的新手。

您收到的异常并没有在转换中发生,但是您会得到一个空指针异常,我认为这种异常是在您尝试创建流时发生的。

var stream = new MemoryStream(byteArray);

您的变量为null,然后尝试从SvgDocument中绘制一个位图,这将使您的流为null。

您需要检查为什么MemoryStream为null / byteArray无效

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM