您是否尝试设置Source
:
var bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.UriSource = new Uri("https://fbcdn-profile-a.akamaihd.net/hprofile-ak-prn2/187738_100000230436565_1427264428_q.jpg");;
bitmapImage.EndInit();
img.Source = bitmapImage;
这是更多信息。
编辑
有可能这不适用于远程图像(目前无法测试),我相信在这种情况下您需要下载图像,所以这是您的操作方法:
var imgUrl = new Uri("https://fbcdn-profile-a.akamaihd.net/hprofile-ak-prn2/187738_100000230436565_1427264428_q.jpg");
var imageData = new WebClient().DownloadData(imgUrl);
// or you can download it Async won't block your UI
// var imageData = await new WebClient().DownloadDataTaskAsync(imgUrl);
var bitmapImage = new BitmapImage {CacheOption = BitmapCacheOption.OnLoad};
bitmapImage.BeginInit();
bitmapImage.StreamSource = new MemoryStream(imageData);
bitmapImage.EndInit();
return bitmapImage;