silverlight
发布时间:2022-05-04 发布网站:大佬教程 code.js-code.com
大佬教程收集整理的这篇文章主要介绍了在Silverlight中读取指定URL图片包数据,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
概述
在silverlight开发,允许我们获取指定URL压缩包(zip)并读取其中的图片文件。而实现这个功能也非常简单。下面是运行效果图:
首先,我们需要建立一个silverligth application ,名称为:DownLoadImg.
下面就是
相应的page.xaml代码: < Grid x:Nam
在silverlight开发,允许我们获取指定URL压缩包(zip)并读取其中的图片文件。而实现这个功能也非常简单。下面是运行效果图:
首先,我们需要建立一个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.openReadCoR_268_11845@pleted
OpenReadCoR_268_11845@pletedEventHandler(wc_OpenReadCoR_268_11845@pleted);
wc.DownloadProgressChanged
DownloadProgressChangedEventHandler(wc_DownloadProgressChanged);
开始异步读取压缩包中的文件信息
wc.openReadAsync(
Uri(
img.zip
, UriKind.RelativE), ImageList.SELEctedItem);
}
wc_OpenReadCoR_268_11845@pleted(
:rgb(0, OpenReadCoR_268_11845@pletedEventArgs E)
{
实例化流资源信息,准备获取其中的图片数据
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(
:rgb(0, DownloadProgressChangedEventArgs E)
{
下载过程中的进度显示
progressText.Text
e.ProgressPercentage.ToString()
+
%
;
progressRectangle.Width
(
double
)e.ProgressPercentage
*
2
; } } }
大佬总结
以上是大佬教程为你收集整理的在Silverlight中读取指定URL图片包数据全部内容,希望文章能够帮你解决在Silverlight中读取指定URL图片包数据所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。