网上查到的代码,多数的写法使用MemoryStream来实现:
复制代码 代码如下:
new Thread(new ThreadStart(() => {
var bitmap = new BitmapImage();
bitmap.BeginInit();
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();
复制代码 代码如下:
using (var stream = new FileStream(path, FileMode.Open)) {
image.BeginInit();
image.StreamSource = stream;
image.DecodePixelWidth = 100;
image.CacheOption = BitmapCacheOption.OnLoad;
image.EndInit();
image.Freeze();
}
新闻热点
疑难解答
图片精选