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,438
  • 68
  • 55
  • 126
SaphuA
  • 2,984
  • 3
  • 38
  • 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,459
  • 5
  • 69
  • 108
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
  • 2,468
  • 7
  • 25
  • 32