0

I am using the following code in my application.

string imageUrl = "https://imageUrl.png/"; //This is a valid url. I can see the image when I paste the url into my web browser
var url = new NSUrl(imageUrl);
using (CGImageSource source = CGImageSource.FromUrl(url))
{
    if (source != null)
    {
        //I never get here
    }
}

Why is source always null? I've tried many different imageUrls, all with the same result.

Dave
  • 3,676
  • 4
  • 28
  • 39
  • are you testing the url from your desktop browser, or from the test device's browser? – Jason Aug 15 '18 at 19:25
  • I had only tested from my desktop browser, but I just tried a few urls from my device's browser, and I was able to see the images on the device. – Dave Aug 15 '18 at 19:35

1 Answers1

1

Your photo address seems to be HTTPS prefix.which is different from HTTP.You can try another URL be HTTP prefix.If the address must be HTTPS,I suggest you use some SDK.

or you can use the following code,they works when use http

string str = ""; //your image url

NSData ImageData = NSData.FromUrl(new NSUrl(str) );
UIImage image = new UIImage(ImageData);
   if (image != null)
        {
            Console.Write("success");
        }
        else
        {
            Console.Write("fail");
        }
Lucas Zhang
  • 18,630
  • 3
  • 12
  • 22