我一直在尝试使用C#将SVG图像转换为PNG,而不必编写太多代码.有人可以推荐一个库或示例代码来执行此操作吗?
我正在尝试将我的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)