3

我正在使用以下方法从现有图像创建 BitmapImage:

BitmapImage bmp = new BitmapImage();
bmp.BeginInit();
bmp.UriSource = new Uri(jpegPath, UriKind.Relative);
bmp.EndInit();

完成此操作后,我想从硬盘驱动器中删除图像,但它已被锁定。有没有办法可以解锁它以便将其删除?

4

2 回答 2

3

bmp.CacheOption = BitmapCacheOption.OnLoad;

这会将图像完全加载到内存中,并且不会在图像文件上留下锁定。

于 2011-05-09T18:34:31.497 回答
0

JPG 仍设置为应用程序中现有对象的来源。尝试将 BitmapImage 的来源设置为其他内容或将其完全删除。或者在内存中创建 JPG 的副本。

于 2011-02-25T11:19:39.767 回答