网上查到的代码,多数的写法使用MemoryStream来实现:
using (var stream = new MemoryStream(File.ReadAllBytes(...))) {
bitmap.StreamSource = stream;
bitmap.CacheOption = BitmapCacheOption.OnLoad;
bitmap.EndInit();
bitmap.Freeze();
}
this.Dispatcher.Invoke((Action)delegate {
Image1.Source = bitmap;
});
})).Start();
image.DecodePixelWidth = 100;
image.CacheOption = BitmapCacheOption.OnLoad;
image.EndInit();
image.Freeze();
}
基于.NET BitmapImage 内存释放问题的解决方法详解
原文:http://www.jb51.net/article/36857.htm