public void ReadPixelSucceeds() { var info = new SKImageInfo(10, 10); var ptr1 = Marshal.AllocCoTaskMem(info.BytesSize); var pix1 = new SKPixmap(info, ptr1); var ptr2 = Marshal.AllocCoTaskMem(info.BytesSize); var result = pix1.ReadPixels(info, ptr2, info.RowBytes); Assert.True(result); }
public static Bitmap ToBitmap(this SKPixmap skiaPixmap) { var info = skiaPixmap.Info; // destination values var config = Bitmap.Config.Argb8888; var dstInfo = new SKImageInfo(info.Width, info.Height); // try keep the pixel format if we can switch (info.ColorType) { case SKColorType.Alpha8: config = Bitmap.Config.Alpha8; dstInfo.ColorType = SKColorType.Alpha8; break; case SKColorType.Rgb565: config = Bitmap.Config.Rgb565; dstInfo.ColorType = SKColorType.Rgb565; dstInfo.AlphaType = SKAlphaType.Opaque; break; #pragma warning disable CS0618 // Type or member is obsolete case SKColorType.Argb4444: config = Bitmap.Config.Argb4444; dstInfo.ColorType = SKColorType.Argb4444; break; #pragma warning restore CS0618 // Type or member is obsolete } // destination bitmap var bmp = Bitmap.CreateBitmap(info.Width, info.Height, config); var ptr = bmp.LockPixels(); // copy var success = skiaPixmap.ReadPixels(dstInfo, ptr, dstInfo.RowBytes); // confirm bmp.UnlockPixels(); if (!success) { bmp.Recycle(); bmp.Dispose(); bmp = null; } return(bmp); }
public static void ToSKPixmap(this Pixbuf pixbuf, SKPixmap pixmap) { // TODO: maybe keep the same color types where we can, instead of just going to the platform default var info = new SKImageInfo(pixbuf.Width, pixbuf.Height); using (var temp = new SKPixmap(info, pixbuf.Pixels)) { temp.ReadPixels(pixmap); if (info.ColorType == SKColorType.Bgra8888) { SKSwizzle.SwapRedBlue(pixmap.GetPixels(), info.Width * info.Height); } } }