BitmapImage in WPF does lock file

Nasenbaer picture Nasenbaer · Jun 21, 2011 · Viewed 12.7k times · Source

I use:

Dim bmi As New BitmapImage(New Uri(fiInfo.FullName, UriKind.Absolute))
bmi.CacheOption = BitmapCacheOption.OnLoad

this does not Use OnLoad And file still is locked to overwrite on harddisk. Any idea how to unlock?

Regards

Answer

CodeNaked picture CodeNaked · Jun 21, 2011

As shown in the question you link to, you'd need to call BeginInit and EndInit, like so as well as set the UriSource property:

Dim bmi As New BitmapImage()
bmi.BeginInit()
bmi.CacheOption = BitmapCacheOption.OnLoad
bmi.UriSource = New Uri(fiInfo.FullName, UriKind.Absolute)
bmi.EndInit()