using System.Collections; using System.Collections.Generic; using SkiaSharp; using UnityEngine; namespace BITKit.UX { public static class SkiaExtensions { public static Texture2D ToTexture2D(this SKImageInfo info,SKSurface surface) { // Okay, we're finished drawing. Now we create a Unity texture. TextureFormat format = (info.ColorType == SKColorType.Rgba8888) ? TextureFormat.RGBA32 : TextureFormat.BGRA32; var texture = new Texture2D(info.Width, info.Height, format, false, true); texture.wrapMode = TextureWrapMode.Clamp; // Pull a Skia image object out of the canvas... var pixmap = surface.PeekPixels(); // Copy it to the Unity texture... texture.LoadRawTextureData(pixmap.GetPixels(), pixmap.RowBytes * pixmap.Height); texture.Apply(false, true); // And drop it into the RawImage object. return texture; } public static SKColor ToSKColor(this Color color,byte? alpha=null) { return new SKColor((byte)(color.r * 255), (byte)(color.g * 255), (byte)(color.b * 255), alpha??(byte)(color.a * 255)); } public static SKColor ToSKColor(this Color32 color) { return new SKColor(color.r, color.g, color.b, color.a); } } }