[英]Xamarin Forms Image Loading Error
我想以“ 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
我已经测试过图像的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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.