Search code examples
.netwpfvb.netbitmapimagelocked

BitmapImage in WPF does lock file


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


Solution

  • 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()