Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mntone/svgforxaml
Draw SVG image with Win2D
https://github.com/mntone/svgforxaml
direct2d draw-images svg uwp win2d winrt winrt-uwp xaml
Last synced: 3 days ago
JSON representation
Draw SVG image with Win2D
- Host: GitHub
- URL: https://github.com/mntone/svgforxaml
- Owner: mntone
- License: mit
- Created: 2015-12-12T12:29:34.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2020-08-26T14:41:50.000Z (about 4 years ago)
- Last Synced: 2024-10-02T07:17:33.851Z (about 1 month ago)
- Topics: direct2d, draw-images, svg, uwp, win2d, winrt, winrt-uwp, xaml
- Language: C#
- Homepage:
- Size: 950 KB
- Stars: 94
- Watchers: 12
- Forks: 18
- Open Issues: 10
-
Metadata Files:
- Readme: readme.md
- License: LICENSE.txt
Awesome Lists containing this project
- awesome-uwp - Svg for Xaml Library - Draw images from svg file with Win2D. (UI Library)
README
# Svg for Xaml Library
[![NuGet](https://img.shields.io/nuget/v/Mntone.SvgForXaml.svg?style=flat-square)](https://www.nuget.org/packages/Mntone.SvgForXaml/) [![Downloads](https://img.shields.io/nuget/dt/Mntone.SvgForXaml.svg?style=flat-square)](https://www.nuget.org/packages/Mntone.SvgForXaml/) [![License](https://img.shields.io/github/license/mntone/SvgForXaml.svg?style=flat-square)](https://github.com/mntone/SvgForXaml/blob/master/LICENSE.txt)
Draw images from svg file with Win2D.
Tokyo railmaps
Thanks to [railmaps](https://github.com/hashcc/railmaps)
## Requirement
- [Win2D](https://github.com/Microsoft/Win2D)
## Usage
### xaml with binding
Binding content type is `SvgDocument`.
```xml
```
### Renderer a raster image from svg image
```csharp
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
```csharp
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
}
```## Note
**If you build your app for Windows 10 Aniversary Update or later, you should use SVG API on Direct2D.**
- Direct2D: https://msdn.microsoft.com/en-us/library/windows/desktop/mt790715.aspx, or
- Win2D: https://microsoft.github.io/Win2D/html/N_Microsoft_Graphics_Canvas_Svg.htm## LICENSE
[MIT License](https://github.com/mntone/SvgForXaml/blob/master/LICENSE.txt)
## Author
- mntone
GitHub: https://github.com/mntone
Twitter: https://twitter.com/mntone (posted in Japanese; however, english is ok)