有没有相对简单的方法来处理SVG.NET中的图像?
PS我正在使用SFML作为图形输出引擎.
目前有哪些方法可以使用C#以编程方式将SVG图像转换为PNG或JPEG?
我已经阅读了有关该主题的所有现有SO问题,所有这些问题都涉及使用外部流程来启动第三方程序.就我而言,这不是一个选项,因为我们很快就会迁移到Azure.
我需要做的是从磁盘加载SVG文件,理想情况下将其转换为我可以使用System.Drawing类进行操作的东西.
有任何想法吗?
我正在尝试将我的svg转换为我一直在寻找几种工具的图像,但仍然无法实现这一点:(
1. SVG渲染引擎, 但由于它没有文档,我遇到了麻烦
这是我的代码:
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);
}
Run Code Online (Sandbox Code Playgroud)
或这个:
var sampleDoc = SvgDocument.Open(@"C:\sample.svg");
sampleDoc.Draw().Save(@"C:\sample.png");
Run Code Online (Sandbox Code Playgroud)
既不起作用!
我收到错误:
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 …Run Code Online (Sandbox Code Playgroud)