Draw SVG graphic with SharpDX
See the question and my original answer on StackOverflowIf you start from the AdvancedTextRenderingApp sample, just modify the render loop so it looks like this:
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();
}
});
And here is the result:
Note 1: you will need the SharpDX.Direct2D1 prerelease package (my version is 4.1.0-ci217), otherwise the crucial CreateSvcDocument
will not be available for some reason.
Note 2: ID2D1DeviceContext5 (DeviceContext5 in SharpDX) requires Windows 10 Creators Update.