Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 658
Nasenbaer Avatar asked Jun 21 '11 18:06

Nasenbaer


2 Answers

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()
like image 108
CodeNaked Avatar answered Nov 08 '22 07:11

CodeNaked


Read the BitmapImage from file and rewrite it with a MemoryStream:

MemoryStream ms = new MemoryStream();
BitmapImage bi = new BitmapImage();
byte[] bytArray = File.ReadAllBytes(@"test.jpg");
ms.Write(bytArray, 0, bytArray.Length);ms.Position = 0;
bi.BeginInit();
bi.StreamSource = ms;
bi.EndInit();
image.Source = bi;
like image 9
Navid Rahmani Avatar answered Nov 08 '22 08:11

Navid Rahmani