wpf 中images控件binding显示图片后,图片文件会一直被占用吗?如果是该怎么解
发布网友
发布时间:2022-05-06 07:38
我来回答
共1个回答
热心网友
时间:2023-10-08 17:12
using (var stream = new FileStream(fileName, FileMode.Open))
{
var bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.StreamSource = stream;
bitmapImage.EndInit();
bitmapImage.Freeze(); // just in case you want to load the image in another thread
return bitmapImage;
}
用这个