6

I am reading my WPF imagesource like this:

VB

Dim bmi As BitmapImage = New BitmapImage
bmi.BeginInit
bmi.CacheOption = BitmapCacheOption.None
bmi.CreateOptions = BitmapCreateOptions.IgnoreImageCache
bmi.UriSource = New Uri(input.FullName, UriKind.Absolute)
bmi.EndInit

C#

BitmapImage bmi = new BitmapImage();
bmi.BeginInit();
bmi.CacheOption = BitmapCacheOption.None;
bmi.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
bmi.UriSource = new Uri(input.FullName,  UriKind.Absolute);
bmi.EndInit();

It works like it should until this point. But user can update the image by copying the file. Then I want to refresh the image. But the file "MyFileName" is locked and when I want do overwrite it, it throws an error that it is already in use and locked.

But wait, I searched here for a solution and I got it:

bmi.cachoption = OnLoad

was the key... BUT!! now, the image is always the old one and is not updated to the new file. How to clear this cache?

In VB.Net I made an System.Drawing.Bitmap from stream. How to do it best way in WPF?

Regards

Nasenbaer
  • 4,810
  • 11
  • 53
  • 86
goldengel
  • 611
  • 8
  • 22
  • see if http://stackoverflow.com/questions/2097152/creating-wpf-bitmapimage-from-memorystream-png-gif helps? i don't know how to clear the cache explicity, but this may help you anyway. – Can Poyrazoğlu Aug 19 '11 at 13:15

1 Answers1

9

dlev had a good advice. Here you see the cache option that should solve it: Problems overwriting (re-saving) image when it was set as image source

imgTemp.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
Gabriel
  • 377
  • 1
  • 3
  • 15
Nasenbaer
  • 4,810
  • 11
  • 53
  • 86