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