Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xamarin:CGImageSource.FromUrl返回null_Xamarin_Xamarin.ios_Cgimage_Ios11.4 - Fatal编程技术网

Xamarin:CGImageSource.FromUrl返回null

Xamarin:CGImageSource.FromUrl返回null,xamarin,xamarin.ios,cgimage,ios11.4,Xamarin,Xamarin.ios,Cgimage,Ios11.4,我正在我的应用程序中使用以下代码 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

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

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
总是空的?我尝试了许多不同的
imageURL
,都得到了相同的结果。

您的照片地址似乎是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");
        }

您是从桌面浏览器还是从测试设备的浏览器测试url?我只从桌面浏览器进行了测试,但我刚刚从设备的浏览器中尝试了一些url,我能够看到设备上的图像。我提供了地址,您可以将文件导入到项目中。