Windows Phone 7 Image控件显示网络图片的两种方式

方法一:

private void button1_Click(object sender, RoutedEventArgs e) 
        { 
            WebClient webClientImgDownloader = new WebClient(); 
            webClientImgDownloader.OpenReadCompleted += new OpenReadCompletedEventHandler(webClientImgDownloader_OpenReadCompleted); 
            webClientImgDownloader.OpenReadAsync(new Uri("http://dilbert.com/dyn/str_strip/000000000/00000000/0000000/000000/80000/5000/100/85108/85108.strip.print.gif", UriKind.Absolute)); 
        } 
 
        void webClientImgDownloader_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e) 
        { 
            BitmapImage bitmap = new BitmapImage(); 
            bitmap.SetSource(e.Result); // ERROR HERE! 
            image1.Source = bitmap; 
方法二:

         //将本地资源文件到Image控件上,图片的Bulid Action属性要设置成Content

         Uri uri = new Uri("/Images/meinv.jpg", UriKind.Relative); 

         //直接将网络图片显示到Image控件上

         Uri uri2 = new Uri("http://www2.ff369.com/tupian/201103/010/1.jpg",UriKind.Absolute);



         ImageSource imgSource = new BitmapImage(uri);

         image1.Source = imgSource;

 

        //当资源图片资源文件的属性是Resource时,使用下面的方法将图片呈现到Image控件上,但是不建议使用这种方法

        //在网上查看资料说将图片以Resource会造成闪屏

        Stream stream = App.GetResourceStream(new Uri("/DemoCode2;component/Images/meinv.jpg", UriKind.Relative)).Stream;


         BitmapImage bitmap = new BitmapImage(); 
         bitmap.SetSource(stream ); // ERROR HERE! 
         image1.Source = bitmap; 

}


 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值