[英]C# .svg file to System.Drawing.Image
我需要將選定的 .svg 文件轉換為 System.Drawing.Image 對象,以便我可以調整它的大小並將其另存為 .png。 誰能幫我這個?
這是我到目前為止所擁有的:
Svg.SvgDocument svgDocument = SVGParser.GetSvgDocument(mPath);
image = svgDocument.Draw();
但它給了我內存不足的錯誤。
您可以使用SVG Rendering Engine Lib ,使用它繪制圖像非常容易:
var svgDoc = SvgDocument.Open(imagePath);
using(var Image = new Bitmap(svgDoc.Draw()))
{
Image.Save(context.Response.OutputStream, ImageFormat.Png);
context.Response.ContentType = "image/png";
context.Response.Cache.SetCacheability(HttpCacheability.Public);
context.Response.Cache.SetExpires(DateTime.Now.AddMonths(1));
}
在此示例中,我使用處理程序在瀏覽器上顯示圖像,但您只需更改 Save 方法的第一個參數即可輕松將其保存在某個文件夾中。
Miljan Vulovic 使用的資源是 svg ( https://archive.codeplex.com/?p=svg )。
鏈接僅在 2021 年 7 月之前有效,屆時可能會在 GitHub 上提供,但我不確定。
無論如何,他的解決方案對我有用。
所以,
SVGParser.MaximumSize = new System.Drawing.Size(4000, 4000);
svgDocument = SVGParser.GetSvgDocument(mPath);
var bitmap = svgDocument.Draw();
image = bitmap;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.