Created
December 17, 2016 16:02
-
-
Save Arlorean/ef9bb3fdec00e9ff522372ce7133c9f8 to your computer and use it in GitHub Desktop.
View SVG in WPF Window using SkiaSharp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Windows; | |
using System.Windows.Controls; | |
namespace WpfApplication2 { | |
public partial class MainWindow : Window { | |
public MainWindow() { | |
InitializeComponent(); | |
var svg = new SkiaSharp.SKSvg(); | |
var picture = svg.Load("Tiger.svg"); | |
var visual = new SkiaSharp.Views.WPF.SKElement(); | |
visual.PaintSurface += (o, a) => { | |
var fit = a.Info.Rect.AspectFit(svg.CanvasSize.ToSizeI()); | |
a.Surface.Canvas.Scale(fit.Width/svg.CanvasSize.Width); | |
a.Surface.Canvas.DrawPicture(picture); | |
}; | |
(this.Content as Grid).Children.Add(visual); | |
} | |
} | |
} |
Author
Arlorean
commented
Dec 17, 2016
- Create a new WPF Project.
- Edit MainWindow.xaml.cs and put this code in it (Change namespace to match your namespace).
- Google Tiger.svg for an example SVG.
- Here is the NuGet packages.cfg:
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment