如果您从
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
.