-
Notifications
You must be signed in to change notification settings - Fork 241
Expand file tree
/
Copy pathSkiaDrawingHelper.cs
More file actions
29 lines (25 loc) · 959 Bytes
/
SkiaDrawingHelper.cs
File metadata and controls
29 lines (25 loc) · 959 Bytes
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
using System;
using System.Drawing;
using SkiaSharp;
namespace ST.Library.UI.NodeEditor {
public static class SkiaDrawingHelper {
public static SKColor ToSKColor(Color color) {
return new SKColor(color.R, color.G, color.B, color.A);
}
public static SKRect ToSKRect(Rectangle rect) {
return new SKRect(rect.Left, rect.Top, rect.Right, rect.Bottom);
}
public static SKBitmap ToSKBitmap(Image image) {
if (image == null) return null;
using (var ms = new System.IO.MemoryStream()) {
image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
ms.Position = 0;
return SKBitmap.Decode(ms);
}
}
public static void RenderToCanvas(SKCanvas canvas, Action<SKCanvas> renderAction) {
if (canvas == null || renderAction == null) return;
renderAction(canvas);
}
}
}