0

我在我的应用程序中使用以下代码。

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
    }
}

为什么source总是为空?我尝试了很多不同imageUrls的方法,结果都一样。

4

1 回答 1

1

你的照片地址好像是HTTPS前缀,和HTTP不一样。你可以试试别的URL是HTTP前缀。如果地址必须是HTTPS,我建议你使用一些SDK。

或者您可以使用以下代码,它们在使用 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");
        }
于 2018-08-16T02:34:12.777 回答