我在Direct2D的C#中使用SharpDX。
对于SVG我发现SharpDX支持它:https://github.com/sharpdx/SharpDX/pull/954/files#diff-ab708c02d6344a22d99b1c932b72cc12
如何渲染SVG图形?
发布于 2018-02-11 03:39:32
如果从AdvancedTextRenderingApp示例开始,只需修改渲染循环,使其如下所示:
RenderLoop.Run(mainForm, () =>
{
renderTarget.BeginDraw();
renderTarget.Clear(bgcolor);
// get an ID2D1DeviceContext5 interface. It will fail here if Windows is not version 1704+
using (var ctx = renderTarget.QueryInterface<DeviceContext5>())
{
// create WIC factory
using (var imagingFactory = new ImagingFactory())
{
// load a file as a stream using WIC
using (var file = File.OpenRead("whale.svg"))
{
using (var stream = new WICStream(imagingFactory, file))
{
// create the SVG document
using (var doc = ctx.CreateSvgDocument(stream, new Size2F(mainForm.Width, mainForm.Height)))
{
// draw it on the device context
ctx.DrawSvgDocument(doc);
}
}
}
}
}
try
{
renderTarget.EndDraw();
}
catch
{
CreateResources();
}
});
结果如下:
注意1:您将需要SharpDX.Direct2D1预发布包(我的版本是4.1.0-ci217),否则由于某种原因,关键的CreateSvcDocument
将不可用。
注2:ID2D1DeviceContext5 (SharpDX中的DeviceContext5)需要Windows 10 Creators Update。
https://stackoverflow.com/questions/48690038
复制相似问题