/SvgForXaml

Draw image from svg file with Win2D

Primary LanguageC#MIT LicenseMIT

Svg for Xaml Library

NuGet Downloads License

Draw images from svg file with Win2D.

app screenshot

Tokyo railmaps

app screenshot

Thanks to railmaps

Requirement

Usage

xaml with binding

Binding content type is SvgDocument.

<svg:SvgImage Content="{Binding ...}" />

Renderer a raster image from svg image

var svg = SvgDocument.Parse(...);
var uri = new Uri("ms-appdata:///local/filename.jpg");
var file = await StorageFile.GetFileFromApplicationUriAsync(uri);
await SvgImageRenderer.RendererImageAsync(file, new SvgImageRendererSettings()
{
	Document = svg,
	Format = SvgImageRendererFileFormat.Jpeg,
	Scaling = 10.0F,
	Quality = 0.8F,
});

Rendering in Win2D ecosystem

var svg = SvgDocument.Parse(...);

var width = 24.0F;
var height = 24.0F;
var scaling = 3.0F;
var device = CanvasDevice.GetSharedDevice();
using (var offScreen = new CanvasRenderTarget(device, width, height, scaling * 96.0F))
using (var renderer = new Win2dRenderer(offScreen, svg))
using (var session = offScreen.CreateDrawingSession())
{
	session.Clear(Colors.Transparent);
	renderer.Renderer(width, height, session); // <- rendering svg content
}

LICENSE

MIT License

Author