Skip to content

Instantly share code, notes, and snippets.

@emoacht
Last active July 25, 2023 23:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emoacht/2204caf09e2993f11fdef4f9ceb870ea to your computer and use it in GitHub Desktop.
Save emoacht/2204caf09e2993f11fdef4f9ceb870ea to your computer and use it in GitHub Desktop.
Get BitmapImage from SKImage of SkiaSharp
using System.IO;
using System.Windows.Media.Imaging;
using SkiaSharp;
public static class SKHelper
{
public static BitmapImage Convert(string filePath)
{
using SKImage image = SKImage.FromEncodedData(filePath);
using SKData encoded = image.Encode(); // PNG format
using Stream stream = encoded.AsStream();
var bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.StreamSource = stream;
bitmapImage.EndInit();
bitmapImage.Freeze();
return bitmapImage;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment