【问题标题】:Xamarin Forms Image Loading ErrorXamarin 窗体图像加载错误
【发布时间】:2017-10-21 02:25:53
【问题描述】:

我想在“Xamarin 表单”中显示图像,但出现以下错误:

Image Loading: Error getting stream for http://www.example.com/example.jpg *(example only)*: System.Net.Http.HttpRequestException: An error occurred while sending the request ---> System.Net.WebException: Error: NameResolutionFailure

我测试过图片的网址,可以在浏览器上显示。

以下是我在代码隐藏中的代码:

var imageSource = new UriImageSource { Uri = new Uri("http://www.Example.com/example.jpg") } ;
            image.Source = imageSource;

下面是我在 Xaml 中使用的代码:

<Image x:Name="image" />

在google了解决方案后,我发现ModernHttpClient可能是一个解决方案,但我不知道如何实现它。

或者不使用 ModernHttpClient 就无法解决错误?

请指教!

【问题讨论】:

  • Error: NameResolutionFailure 无论您实际使用的是什么 url,域名都没有解析....

标签: c# xamarin xamarin.forms


【解决方案1】:

试试这个

string imageURI = "https://s9.postimg.org/aq1jt3fu7/handshake.87122244_std.jpg";
System.Uri uri;

async void LoadImage()
{
    System.Uri.TryCreate(imageURI, UriKind.Absolute, out uri);
    Task<ImageSource> result = Task<ImageSource>.Factory.StartNew(() => ImageSource.FromUri(uri));
    img.Source = await result;
}

【讨论】:

    【解决方案2】:

    我已经解决了这个问题。

    这是因为默认情况下,模拟器没有配置连接到互联网,因此无法从互联网加载图像。

    This是配置模拟器网卡的解决方案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-05
      • 1970-01-01
      • 2017-11-11
      • 2012-10-11
      • 2018-09-06
      • 2018-02-01
      • 1970-01-01
      相关资源
      最近更新 更多