C# Xamarin表单图像加载错误
我想在“Xamarin表单”中显示图像,但出现以下错误:C# Xamarin表单图像加载错误,c#,xamarin,xamarin.forms,C#,Xamarin,Xamarin.forms,我想在“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: NameRe
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
我已经测试了图像的URL,它能够显示在浏览器上
下面是我在代码隐藏中的代码:
var imageSource = new UriImageSource { Uri = new Uri("http://www.Example.com/example.jpg") } ;
image.Source = imageSource;
下面是我在Xaml中使用的代码:
<Image x:Name="image" />
在我搜索解决方案后,我发现ModernHttpClient可能是一个解决方案,但我不知道如何实现它
或者,如果不使用ModernHttpClient,我不可能解决错误吗
请指教 试试这个
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;
}
字符串imageURI=”https://s9.postimg.org/aq1jt3fu7/handshake.87122244_std.jpg";
System.Uri;
异步void LoadImage()
{
System.Uri.TryCreate(imageURI、UriKind.Absolute、out-Uri);
任务结果=Task.Factory.StartNew(()=>ImageSource.FromUri(uri));
img.Source=等待结果;
}
我已经解决了这个问题
这是因为默认情况下,模拟器未配置为连接到internet,因此无法从internet加载映像
是配置仿真器网卡的解决方案。
错误:NameResolutionFailure
无论您实际使用的是什么url,域名都未解析。。。。