Professional, Software

Using Resources out of ZIP

using Silverlight Alpha 1.1, you can zip your images/media files and use them in your application using downloader class. It is pretty straightforward.

  1. Download zip file using Downloader class
  2. hook the completed event for the Downloader class
  3. Use image.SetSource API that takes Downloader object and part name to set the image source

page.xaml

<Canvas 
        xmlns="http://schemas.microsoft.com/client/2007" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        x:Name="parentCanvas" 
        Loaded="Page_Loaded" 
        x:Class="zippedimages.Page;assembly=ClientBin/zippedimages.dll" 
        Width="640" 
        Height="480" 
        Background="White" 
        > 
    <Image Width="350" Height="250.757" Canvas.Left="152" 
         Canvas.Top="119.129" x:Name="image" /> 
</Canvas>

page.xaml.cs

using System; 
using System.Windows; 
using System.Windows.Controls; 

namespace zippedimages 
{ 
    public partial class Page : Canvas 
    { 
        public void Page_Loaded(object o, EventArgs e) 
        { 
            // Required to initialize variables 
            InitializeComponent(); 
            Downloader d = new Downloader(); 
            d.Open("GET", new Uri("images.zip", UriKind.Relative), true); 
            d.Completed += new EventHandler(d_Completed); 
            d.Send(); 
        } 

        void d_Completed(object sender, EventArgs e) 
        { 
            Downloader d = (Downloader)sender; 
            image.SetSource(d, "image1.jpg"); 
        } 
    } 
}

Unfortunately there is no way today to just download the image directly and get a stream for that image and set the source of image element using that stream.

Source code for this simple project is here.

Advertisements
Standard

3 thoughts on “Using Resources out of ZIP

  1. hello.
    yes, we can get the image bytes but there’s no way to feed an image (or other media element) with those bytes. are you guys going to add that feature on the next release? it’s becoming a big limitation for somethings i wanted to build with silverlight…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s