-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.cs
42 lines (35 loc) · 1.27 KB
/
Form1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System;
using System.Drawing;
using System.Windows.Forms;
using SkiaSharp;
using SkiaSharp.Views.Desktop;
namespace SkiaWinform
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
_skControl.PaintSurface += OnPaintSurface;
}
private void OnPaintSurface(object sender, SKPaintSurfaceEventArgs e)
{
var icon = SystemIcons.Information;
var skBitmap = icon.ToBitmap().ToSKBitmap();
var info = e.Info;
var surface = e.Surface;
float scale = Math.Min((float)info.Width / skBitmap.Width, (float)info.Height / skBitmap.Height);
float x = (info.Width - scale * skBitmap.Width) / 2;
float y = (info.Height - scale * skBitmap.Height) / 2;
SKRect destRect = new SKRect(x, y, x + scale * skBitmap.Width,
y + scale * skBitmap.Height);
using (var paint = new SKPaint())
{
paint.IsAntialias = true;
paint.FilterQuality = SKFilterQuality.None;
e.Surface.Canvas.Clear();
e.Surface.Canvas.DrawBitmap(skBitmap, destRect, paint);
}
}
}
}