后台代码:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 using System;
2 using System.Windows;
3 using System.Windows.Controls;
4 using System.Windows.Documents;
5 using System.Windows.Ink;
6 using System.Windows.Input;
7 using System.Windows.Media;
8 using System.Windows.Media.Animation;
9 using System.Windows.Shapes;
10 using System.Windows.Browser;
11 using System.IO;
12 using System.Windows.Resources;
13 using System.Windows.Media.Imaging;
14 using System.Net;
15
16 namespace SLStudyDemo15
17 {
18 public partial class SL15_6_7 : UserControl
19 {
20 public SL15_6_7()
21 {
22 // 为初始化变量所必需
23 InitializeComponent();
24 this.load_btn.Click += new RoutedEventHandler(load_btn_Click);
25 P.Maximum = 100;
26 P.Value = 0;
27 }
28 void load_btn_Click(object sender, RoutedEventArgs e)
29 {
30 Uri zipuri = new Uri("/Resource/images.zip", UriKind.Relative);//正确的写法
31 //new Uri(HtmlPage.Document.DocumentUri, "/Resource/images.zip");//错误的写法
32
33 WebClient client = new WebClient();
34 client.OpenReadAsync(zipuri);
35 client.OpenReadCompleted += new OpenReadCompletedEventHandler(client_OpenReadCompleted);
36 client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
37
38 }
39 void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
40 {
41 P.Value = e.ProgressPercentage;
42 }
43 void client_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
44 {
45 if (e.Error == null)
46 {
47 Uri uri = new Uri("1.jpg", UriKind.Relative);
48 StreamResourceInfo zipsri = new StreamResourceInfo(e.Result, null);
49 StreamResourceInfo imagssri = Application.GetResourceStream(zipsri, uri);
50
51 BitmapImage bi = new BitmapImage();
52 bi.SetSource(imagssri.Stream);
53 //this.m.Source = bi;
54 Image img = new Image();
55 img.Width = 100;
56 img.Height = 120;
57 img.Source = bi;
58 H.Children.Add(img);
59 }
60 else
61 {
62 MessageBox.Show(e.Error.Message);
63 }
64 }
65 }
66 }
要注意的地方:
1 文件在工程中的位置
2 图片压缩文件的位置关系,图片不可以在一个文件下,应该直接打包
敏于事,慎于言