Create BitmapImage from byte array.
This file contains 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
public static BitmapImage Create(byte[] bytes) | |
{ | |
var result = new BitmapImage(); | |
using (var stream = new MemoryStream(bytes)) | |
{ | |
result.BeginInit(); | |
result.CacheOption = BitmapCacheOption.OnLoad; | |
result.CreateOptions = BitmapCreateOptions.None; | |
result.StreamSource = stream; | |
result.EndInit(); | |
result.Freeze(); // 非UIスレッドから作成する場合、Freezeしないとメモリリークするため注意 | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment