CaseStudy(showcase)数据篇-加载图片

时间:2022-04-22
本文章向大家介绍CaseStudy(showcase)数据篇-加载图片,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

做silvelight也有一段时间了,相册、游戏,刚刚完成的showcase这个小程序算是一个阶段了。这里就以showcase这个项目来做一下CaseStudy。

数据篇-加载图片

beta1到beta2中加载图片的方法有些改变。

 private void LoadImage(String MediaUrl)
         {
             Uri uri = new Uri(HtmlPage.Document.DocumentUri, MediaUrl);
 
             WebClient imgClient = new WebClient();
             imgClient.OpenReadCompleted += new OpenReadCompletedEventHandler(imgClient_OpenReadCompleted);
             imgClient.OpenReadAsync(uri);
         }
 
 void imgClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
         {
 if (e.Error == null)
             {
                 BitmapImage bi = new BitmapImage();
                 bi.SetSource(e.Result);
                 xImage.Source = bi;
             }
         }
 

 另一种方法

            Uri uri = new Uri(HtmlPage.Document.DocumentUri, MediaUrl);
             ImageSource img = new System.Windows.Media.Imaging.BitmapImage(uri);
             xImage.SetValue(Image.SourceProperty, img);