Use SkiaSharp to encode images in Uno proejcts

7/14/2018

SkiaSharp is a versatile package that can be used on all mobile platforms.

SkiaSharp is a versatile package that can be used on all mobile platforms.  The following code encodes a pixel array to an JPEG image and displays it.

SKImageInfo sii = new SKImageInfo(iWidth, 1, SKColorType.Rgba8888);
SKData sd = SKData.Create(new MemoryStream(abPixels));
SKImage sKImage = SKImage.FromPixelData(sii, sd, iWidth * 4);
SKData sdOut = sKImage.Encode(SKEncodedImageFormat.Jpeg, 100);
BitmapImage bitmapImage = new BitmapImage();

await bitmapImage.SetSourceAsync(sdOut.AsStream().AsRandomAccessStream());
imageIntegratedButton.Source = bitmapImage;

 abPixels is a byte array.  Each pixel corresponds to 4 bytes (R, G, B, A).