Last active
July 25, 2023 23:54
-
-
Save emoacht/2204caf09e2993f11fdef4f9ceb870ea to your computer and use it in GitHub Desktop.
Get BitmapImage from SKImage of SkiaSharp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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