locked
Image and ImageSource.FromUri - where is the error returned if the download failed? RRS feed

  • Question

  • User336563 posted

    Hi,

    We are downloading images from the internet with a Uri which is passed into ImageSource.

    This generally works, but sometimes it doesn't on various .png or .jpg images.

    So, how do these controls return the error that was encountered?

    Br, Karhu.

    Friday, July 14, 2017 12:19 PM

All replies

  • User180523 posted

    Personally I wouldn't rely on the control for that level of robustness. Download the image once in its own call - that you can monitor and get errors from. Store it locally on the device. Now you don't need to download it 20 times. You can even work off-line. Put it in the Image from the locally saved file.

    Friday, July 14, 2017 12:26 PM
  • User336563 posted

    Do you have an example of how to properly download the file?

    Monday, July 17, 2017 9:38 AM
  • User72170 posted

    Here is how you could download the image from url

     public static System.IO.MemoryStream GetImage(string filename)
        {
    
            System.Net.WebClient webClient = new System.Net.WebClient();
            System.IO.MemoryStream stream = new System.IO.MemoryStream();
            webClient.OpenRead(filename).CopyTo(stream);
            return stream;
    
        }
    
    Saturday, June 1, 2019 4:18 AM