从窗口电话中的URL设置图像源

时间:2013-07-16 16:35:53

标签: silverlight windows-phone-7 windows-phone-8

我是从网址设置图片来源,但是没有正确显示图片, 我在Windows Phone 8中使用的代码在下面,提前感谢..

 image1.Source =  new BitmapImage(new Uri("http://d3sdoylwcs36el.cloudfront.net/VEN-virtual-enterprise-network-business-opportunities-small-fish_id799929_size485.jpg",UriKind.Absolute));

结果是 enter image description here

1 个答案:

答案 0 :(得分:2)

我完成了它,为图像调用Web服务..代码在下面..

WebClient webClient = new WebClient();
webClient.OpenReadCompleted += ImageOpenReadCompleted;
webClient.OpenReadAsync(new Uri("http://d3sdoylwcs36el.cloudfront.net/VEN-virtual-enterprise-network-business-opportunities-small-fish_id799929_size485.jpg"));




private void ImageOpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
     if (!e.Cancelled && e.Error == null)
    {
        BitmapImage bmp = new BitmapImage();
        bmp.SetSource(e.Result);
        image1.Source = bmp;
    }
}

完成它......:)