Hey guys,
I am trying to load a stream from a local file, assign to a BitmapImage, and then later in the application, the file may be moved to another location.
I am trying this:
using (var stream = File.OpenRead(fileInfo.FullName))
{
duplicate.Image = new BitmapImage
{
CacheOption = BitmapCacheOption.OnLoad
};
duplicate.Image.BeginInit();
duplicate.Image.StreamSource = stream;
duplicate.Image.EndInit();
}
However the image is not fully loaded (I see a gray rectangle in the UI).
I then tried
var stream = File.OpenRead(fileInfo.FullName);
duplicate.Image = new BitmapImage
{
CacheOption = BitmapCacheOption.OnLoad
};
duplicate.Image.BeginInit();
duplicate.Image.StreamSource = stream;
duplicate.Image.EndInit();
(based on the documentation that says that BitmapCacheOption.OnLoad will close the stream after the BitmapImage is created). However, when I try to move the file, I get an error saying that it is used by another process, yadayadayada.
What am I missing? (NB: Same thing when I try with UriSource).
BTW in XAML I just do
<Image Source="{Binding Image}"
Height="98"
Cursor="Hand">
Cheers
Laurent
--
Laurent Bugnion
Director, UX Integration Development, IdentityMine
Microsoft MVP, MCP
www.galasoft.ch | blog.galasoft.ch
Yeah that was my analysis too. I was hoping to avoid that step…
Cheers!
Laurent