Where is Silverlight's Isolated Storage Image Support?

Where is Silverlight's Isolated Storage Image Support?

Posted in:

Recently, we decided to write a tutorial on how to use Silverlight's isolated storage. In theory, isolated storage is a great feature that allows Silverlight to view offline content. In practice, however, you're pretty limited on what it can be used for.

The example we wanted to use for the tutorial was putting an image into isolated storage and then displaying the image at a later time. For instance, we thought it would be cool if the user could browse to an image on their local computer, and then we could display it in a silverlight app. Currently, the only way to do that would be to actually upload the image to the webserver, and then reference it from there. But we thought it would be really cool if we could just copy the image to the isolated storage space and then display it - getting rid of the time and bandwidth consuming step of uploading the image. While we are able to put an image into the isolated storage space (isolated storage lets you put pretty much whatever you want into the 1MB of available space), we have had no success getting silverlight to read the image back out and display it on the screen.

Silverlight has two elements available for displaying images: Image and ImageBrush. Neither of these elements have the ability to read image data from a file stream, which is required for reading content from isolated storage.

We'd be perfectly happy if you could reference isolated storage using a special uri synax - something like "ifs://myNewImage.jpg", where "ifs" stands for Isolated File Storage, but as far as we can tell, this isn't supported.

We're fully aware that isolated storage was added in 1.1 and is still alpha. That being said, this will be a feature we'll look forward to having in future releases. Reading and writing images to isolated storage would also be a great feature when the browser's caching mechanism is not quite doing what you want - you could store images and other content there by whatever rules you define. We still plan on putting up some tutorials on using isolated storage, but we thought we'd go ahead and post this rant before we create the tutorials.

We have a couple ideas on some ridiculously convoluted ways to make it work, but something that complicated isn't worth using. If someone out there has some insight on this topic, please drop us a line.

Jeff
09/24/2007 - 19:12

MS definitely does need to let us do this!

For now, you might be interested to check out fluxify @ fluxtools.net... although we're not storing images in isolated storage, we implemented the ability to view thumbnails of client-side images, albeit for a different purpose...

reply

Nik Radford
02/14/2008 - 11:03

Wouldn't it just be better to give Image the Image.FromStream support that standard System.Drawing.Image has in .NET rather than creating a faux protocol? :)

reply

Anonymous
06/02/2008 - 01:18

Hi,
You said that you were able to store an image into the isolated storage space. Can you please let me know how you did that.
Thanks

reply

Gopinath Varadharajan
07/03/2008 - 06:36

Hi,

Do u guys figured how to use isolated stored images ? Would be very helpful..

Thanks,

Gopi

reply

Mikael Eliasson
07/30/2008 - 08:03

With the release of beta 2 it should be easy.

In this snippet of code I do almost the same thing. Note that it's some custom things not needed for you, like PictureShell that is specific to the app where I use this.

PictureShell shell = this.DataContext as PictureShell;
           
Stream stream = shell.FileDialogFileInfo.OpenRead();
           
BitmapImage imageSource = new BitmapImage();
            imageSource.SetSource(stream);
           
PreviewImage.Source = imageSource;
           
stream.Close();            
stream.Dispose();

The only difference is that the PictureShell contains the FileDialogInfo so I open the stream from that instead of a file from IS. But I know you can get a stream from an Image in IS so I'm sure it can be done just changing the first steps where you retrive the stream.

Note: PreviewImage is an Image declared in XAML

Hope it helps anyone looking for how to load a local image into a Image element.

reply

Tagnard
08/21/2008 - 08:32

I read your problem and i started building somthing. this works, but may not be the best suloution.

http://tagnard.net/2008/08/20/save-image-in-isolated-storage/

reply

Ahura Mazda
10/24/2008 - 05:20

To load an image from Isolated Storage, you can do this:

IsolatedStorageFile isStore =
    IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream isolatedStorageFileStream  =
    isStore.OpenFile("example.jpg", FileMode.Open);

//assumption:
//example.jpg has already been saved to IsolatedStorage

var bitmapImage = new BitmapImage();                    bitmapImage.SetSource(isolatedStorageFileStream);
Image image = new Image();
image.Source = bitmapImage;

reply

The Tallest
10/24/2008 - 08:27

Yup, we actually just wrote a post about that here - and it is great that Microsoft added that in to Silverlight 2.

reply

Add Comment

Put code snippets inside language tags:
[language] [/language]

Examples:
[javascript] [/javascript]
[actionscript] [/actionscript]
[csharp] [/csharp]

See here for supported languages.

Javascript must be enabled to submit anonymous comments - or you can login.

Sponsors