使用 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 中绘制一个位图,该文档将获取为空的流。
您需要检查为什么您的内存流为空/字节数组无效
相关文章:
- 如何在Edge中下载图像/png数据URI
- 在javaservlet doPost方法中启动线程时,无法返回异常消息
- document.applet.method在Mounatin Lion上抛出safari 6+JDK7异常
- 如何通过ajax将png图片从服务器发送到浏览器中显示
- 为什么浏览器没有为语法错误抛出异常
- java,javascript签名的小程序(文件选择,ftp上传)安全性/套接字异常
- 将SVG下载为PNG图像
- node.js和express中的异常处理
- 派生进程的stdout在管道传输时工作异常
- NodeJS和pg promise,捕获PostgreSQL异常
- 当显式定义控制器参数时,默认模型绑定器会发生异常
- 显示引导弹出操作异常的逻辑
- 调用谷歌地图路线服务时未捕获的异常
- web配置http到https重定向异常
- 转换异常时间&Datestring到JavaScript日期
- 为什么在python中使用异常比javascript更容易接受
- PHP REST服务抛出异常——希望避免控制台错误
- JS异常:animate不是一个函数
- 在蓝鸟中处理异常
- 使用 SVG 渲染引擎将 svg 转换为 png 时出现异常