public class Icon : Frame
{
private readonly SKCanvasView canvasView = new SKCanvasView();
public Icon()
{
Padding = new Thickness(0);
BackgroundColor = Color.Transparent;
HasShadow = false;
Content = canvasView;
canvasView.PaintSurface += CanvasViewOnPaintSurface;
}
private void CanvasViewOnPaintSurface(object sender, SKPaintSurfaceEventArgs args)
{
SKCanvas canvas = args.Surface.Canvas;
canvas.Clear();
if (string.IsNullOrEmpty("SimpleSample.level2.svg"))
return;
using (Stream stream = GetType().Assembly.GetManifestResourceStream("SimpleSample.level2.svg"))
{
SKSvg svg = new SKSvg();
svg.Load(stream);
SKImageInfo info = args.Info;
canvas.Translate(info.Width / 2f, info.Height / 2f);
SKRect bounds = svg.ViewBox;
float xRatio = info.Width / bounds.Width;
float yRatio = info.Height / bounds.Height;
float ratio = Math.Min(xRatio, yRatio);
canvas.Scale(ratio);
canvas.Translate(-bounds.MidX, -bounds.MidY);
canvas.DrawPicture(svg.Picture);
}
}
} |