Xamarin: CGImageSource.FromUrl returning null

161 Views Asked by At

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.

1

There are 1 best solutions below

1
On

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");
        }