Skip to content

Instantly share code, notes, and snippets.

@nuitsjp
Created October 17, 2016 01:27
Embed
What would you like to do?
Create BitmapImage from byte array.
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