Image doesn't display when URL is used

I have an Image (DragImage) on an InkCanvas. I'm replacing the UniformSource property of the image. This process leaves me with an empty image box. If I repeat the process a 2nd time then the box has the appropriate image in it. If I restart the application the problem comes back.

This problem only occurs when the URI is a URL. If I use a UNC page to the same image there is no problem.

Seems like a caching issue of some kind. Any ideas? Can I force the Image to reload after I change the UniformSource?

//element is a reference to a UIElement on the InkCanvas

// This path doesn't work

string path =http://www.mysite.com//LiveImages/10351_hq.jpg;

// This path works

//path ="\\\\server\\d$\\\liveimages\\10351_hq.jpg";

Uri u =newUri(path,UriKind.Absolute);

System.Windows.Media.Imaging.BitmapImage bi =new System.Windows.Media.Imaging.BitmapImage();

bi.BeginInit();

bi.CacheOption = System.Windows.Media.Imaging.BitmapCacheOption.OnLoad;

bi.DecodePixelWidth =Convert.ToInt16(((System.Windows.Media.Imaging.CroppedBitmap)di.Source).Source.Width);

bi.DecodePixelHeight =Convert.ToInt16(((System.Windows.Media.Imaging.CroppedBitmap)di.Source).Source.Height);

bi.UriSource = u;

bi.EndInit();

System.Windows.Media.Imaging.CroppedBitmap cb =new System.Windows.Media.Imaging.CroppedBitmap(bi, cropped.SourceRect);

((DragImage)element).UniformSource = cb;

[2874 byte] By [bes7252] at [2008-1-6]
# 1

I found out what was going on. The BitmapImage bi is loading the image from the URI. It doesn't complete before the last line runs, so the image isn't available yet. I put this line before BeginInit():

bi.DownloadCompleted += new EventHandler(bi_DownloadCompleted);

And moved the last 2 lines into bi_DownloadCompleted. Now all is well.

Brian

bes7252 at 2007-9-28 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...

Visual Studio Orcas

Site Classified