3

I am creating an BitmapImage from an existing image using:

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

After I have done this I want to delete the image from my hard drive, but it is locked. Is there a way I can unlock it so it can be removed?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
SaphuA
  • 3,092
  • 3
  • 39
  • 58

2 Answers2

3

bmp.CacheOption = BitmapCacheOption.OnLoad;

That will load the image into memory completely and won't leave a lock on the image file.

RandomEngy
  • 14,931
  • 5
  • 70
  • 113
0

JPG is still set as the source of existing object in your application. Try to set the source of BitmapImage to something else or remove it completely. Or create a copy of your JPG in memory.

Ondrej Vencovsky
  • 3,188
  • 9
  • 28
  • 34