相关疑难解决方法(0)

使用C#将SVG转换为PNG

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

.net c# svg png

93
推荐指数
4
解决办法
9万
查看次数

以编程方式将svg转换为图像

我正在尝试将我的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)

c# svg image

6
推荐指数
1
解决办法
2万
查看次数

标签 统计

c# ×2

svg ×2

.net ×1

image ×1

png ×1