Skip to content

Instantly share code, notes, and snippets.

@nuitsjp
Created October 17, 2016 01:27
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 nuitsjp/522b0bee4e010ea9e36eeac1d0e57f00 to your computer and use it in GitHub Desktop.
Save nuitsjp/522b0bee4e010ea9e36eeac1d0e57f00 to your computer and use it in GitHub Desktop.
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