locked
Display image from http-address RRS feed

  • Question

  • Hi all,

     

    i want to display a image from a http-address but when the image is not there the complete app cancels and shows a 404 Not found ecxeption. I have no chance to catch these exception, without cancelling the app.

    Is there a way to check for the image before Displaying it?

     

    thanks,

    Herbert

    Tuesday, May 16, 2006 12:52 PM

Answers

  • We are addressing this issue in future builds of WPF.



    For now if you want to work around this you have to try to decode the image in code and then assign the BitmapSource to the Image element’s Source property. Like this you can catch any exceptions that happen.
    Tuesday, May 16, 2006 2:38 PM
  • Sure:



    In your code behind:



    Uri uri = new Uri(…);



    try

    {

    myImageElement.Source = BitmapFrame.Create(uri);

    }

    catch (WebException)

    {

    // handle the 404 issue.

    }
    Tuesday, May 16, 2006 3:38 PM

All replies

  • An idea could be to try to download the image, and if you are able to get it, that mean it's ok

    In that case, you just need to delete the image downloaded and to display it from the URL
    Tuesday, May 16, 2006 1:06 PM
  • Hello Thomas,

    first thanks for your answer.

    The problem is that i display 12 images on one page and i wrote a dataconverter that converts the urlstring in a bitmapsource.

    I tried to load the image in the converter before displaying it but then the performance is very slow.

    thanks,

    Herbert

    Tuesday, May 16, 2006 1:22 PM
  • We are addressing this issue in future builds of WPF.



    For now if you want to work around this you have to try to decode the image in code and then assign the BitmapSource to the Image element’s Source property. Like this you can catch any exceptions that happen.
    Tuesday, May 16, 2006 2:38 PM
  • Hello Robert,

    do you have an example on decoding the image, i dont understand what you mean with decoding?

     

    thanks,

    Herbert

    Tuesday, May 16, 2006 3:10 PM
  • Sure:



    In your code behind:



    Uri uri = new Uri(…);



    try

    {

    myImageElement.Source = BitmapFrame.Create(uri);

    }

    catch (WebException)

    {

    // handle the 404 issue.

    }
    Tuesday, May 16, 2006 3:38 PM