首先,我们需要建立一个silverligth application ,名称为:DownLoadimg.
下面就是相应的page.xaml代码:
< GrID x:name ="LayoutRoot" Background ="White" >
GrID.RowDeFinitions
RowDeFinition Height ="250" /> ="100" ="50" </ StackPanel GrID.Row ="1" ListBox ="ImageList" button ="Download" Click ="StartDownLoad" Content ="下载该图片" StackPanel
="0"
ScrollVIEwer HorizontalScrollbarVisibility ="auto"
Image ="imgToFill"
Image ScrollVIEwer ="2" Canvas Canvas.top ="70" Rectangle name ="progressRectangle" Height ="10" WIDth ="0" Fill ="AliceBlue" Rectangle ="12" WIDth ="202" strokeThickness ="1" stroke ="Black" TextBlock ="progresstext" Canvas.left ="210" Text ="0%" FontSize Canvas
GrID
接下来是 page.xaml.cs(相关内容见注释): using System;
System.Collections.Generic;
System.linq;
System.Net;
System.windows;
System.windows.Controls;
System.windows.documents;
System.windows.input;
System.windows.Media;
System.windows.Media.Animation;
System.windows.Shapes;
System.IO;
System.windows.Resources;
System.windows.Media.Imaging;
namespace DownLoadimg
{
public partial class Page : UserControl
{
WebClIEnt wc = new WebClIEnt();
Page()
{
InitializeComponent();
this .Loaded += RoutedEventHandler(Page_Loaded);
}
// 加载图片列表数据 voID Page_Loaded( object sender, RoutedEventArgs e)
{
ImageList.Items.Add( " 1.jpg " );
ImageList.Items.Add( 2.png );
}
实例化下载设置 StartDownLoad( o, EventArgs e)
{
初始化相应控件信息 imgToFill.Visibility Visibility.Collapsed;
progressRectangle.WIDth 0 ;
progresstext.Text 0% ;
绑定下载过程中处理的事件 wc.OpenReadCompleted OpenReadCompletedEventHandler(wc_OpenReadCompleted);
wc.DownloadProgressChanged DownloadProgressChangedEventHandler(wc_DownloadProgressChanged);
开始异步读取压缩包中的文件信息 wc.OpenReadAsync( Uri( img.zip , UriKind.relative), ImageList.SelectedItem);
}
wc_OpenReadCompleted( {
实例化流资源信息,准备获取其中的图片数据 StreamResourceInfo sri StreamResourceInfo(e.Result as Stream, null );
要读取的图片路径信息 String sURI e.UserState String;
从流资源中获取指定的URL图片流信息 StreamResourceInfo imagestream Application.GetResourceStream(sri,0)"> Uri(sURI, UriKind.relative));
BitmAPImage imgsrc BitmAPImage();
绑定该URL图片信息并进行显示 imgsrc.SetSource(imagestream.Stream);
imgToFill.source imgsrc;
imgToFill.Visibility Visibility.Visible;
imgToFill.Stretch Stretch.Fill;
}
wc_DownloadProgressChanged( {
下载过程中的进度显示 progresstext.Text e.Progresspercentage.ToString() + % ;
progressRectangle.WIDth ( double )e.Progresspercentage * 2 ; } } } 总结
以上是内存溢出为你收集整理的在Silverlight中读取指定URL图片包数据全部内容,希望文章能够帮你解决在Silverlight中读取指定URL图片包数据所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)