Imports System.Windows.Resources
Imports System.IO
Imports System.Windows.Media.Imaging
Partial Public Class PageLong
Inherits UserControl
Private WithEvents webClient As New WebClient
Public Sub New()
InitializeComponent()
' Load an image resource file that is included in a ZIP package
' at the site of origin.
' Specify the zip package with the image resource to get.
Dim uri As New Uri("ZIPPackageWithImage.zip", UriKind.Relative)
' Download the zip package.
webClient.OpenReadAsync(uri)
End Sub
Private Sub webClient_OpenReadCompleted(ByVal sender As Object, _
ByVal e As OpenReadCompletedEventArgs) _
Handles webClient.OpenReadCompleted
' Extract the desired image from the zip package.
Dim zipPackageStream As Stream = e.Result
Dim image As Image = LoadImageFromZipPackage( _
"ImageInZipPackage.png", zipPackageStream)
Me.stackPanel.Children.Add(image)
End Sub
Public Function LoadImageFromZipPackage( _
ByVal relativeUriString As String, _
ByVal zipPackageStream As Stream) As Image
' Get the image stream at the specified URI that
' is relative to the application package root.
Dim uri As New Uri(relativeUriString, UriKind.Relative)
Dim zipPackageSri As New StreamResourceInfo(zipPackageStream, Nothing)
Dim imageSri As StreamResourceInfo = _
Application.GetResourceStream(zipPackageSri, uri)
' Convert the stream to an Image.
Dim bi As New BitmapImage()
bi.SetSource(imageSri.Stream)
Dim img As New Image()
img.Source = bi
Return img
End Function
End Class
using System; // Uri
using System.IO; // Stream
using System.Windows; // Application
using System.Windows.Controls; // TextBlock, Image
using System.Windows.Media.Imaging; // BitmapImage
using System.Net; // WebClient
using System.Windows.Resources; // StreamResourceInfo
namespace SilverlightApplication
{
public partial class PageLong : UserControl
{
public PageLong()
{
InitializeComponent();
// Load an image resource file that is included in a ZIP package
// at the site of origin.
// Specify the zip package with the image resource to get.
Uri uri = new Uri("ZIPPackageWithImage.zip", UriKind.Relative);
// Download the zip package.
WebClient webClient = new WebClient();
webClient.OpenReadCompleted += new OpenReadCompletedEventHandler(
webClient_OpenReadCompleted);
webClient.OpenReadAsync(uri);
}
void webClient_OpenReadCompleted(object sender,
OpenReadCompletedEventArgs e)
{
// Extract the desired image from the zip package.
Stream zipPackageStream = e.Result;
Image image = LoadImageFromZipPackage(
"ImageInZipPackage.png", zipPackageStream);
this.stackPanel.Children.Add(image);
}
public Image LoadImageFromZipPackage(
string relativeUriString, Stream zipPackageStream)
{
// Get the image stream at the specified URI that
// is relative to the application package root.
Uri uri = new Uri(relativeUriString, UriKind.Relative);
StreamResourceInfo zipPackageSri =
new StreamResourceInfo(zipPackageStream, null);
StreamResourceInfo imageSri =
Application.GetResourceStream(zipPackageSri, uri);
// Convert the stream to an Image.
BitmapImage bi = new BitmapImage();
bi.SetSource(imageSri.Stream);
Image img = new Image();
img.Source = bi;
return img;
}
}
}