将图像从外部 URL 加载到 Windows Phone 应用程序中
本文关键字:Windows Phone 应用程序 加载 图像 从外部 URL | 更新日期: 2023-09-27 17:56:27
我正在尝试从特定网址加载一些图像:http://www.example.com/Images/
.
我正在尝试执行以下代码,该代码在从本地文件夹获取图像时有效:
Uri uri = new Uri(filePath + imageName, UriKind.RelativeOrAbsolute);
try
{
StreamResourceInfo resourceInfo = Application.GetResourceStream(uri);
BitmapImage bmp = new BitmapImage();
bmp.SetSource(resourceInfo.Stream);
return bmp;
}
catch (Exception ex)
{
return null;
}
但是,对于外部 URL,它会在 bmp.SetSource
上引发错误。
你能告诉我我做错了什么吗?
不要打扰这些流。只需使用:
BitmapImage img = new BitmapImage(new Uri("https://www.image.url/address.png"));