从外部网址将图像加载到Windows手机应用程序中

时间:2014-04-02 17:45:08

标签: c# xaml image-processing windows-phone-8

我正在尝试从特定网址加载一些图片: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;
}

但是对于外部网址,它会在bmp.SetSource上抛出错误。

你能告诉我我做错了什么吗?

1 个答案:

答案 0 :(得分:2)

不要为这些流而烦恼。只需使用:

BitmapImage img = new BitmapImage(new Uri("https://www.image.url/address.png"));
相关问题