Switch On The Code RSS Button - Click to Subscribe
Sep
24

Where is Silverlight’s Isolated Storage Image Support?

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.



Posted in Rants, Silverlight, All Tutorials by The Reddest |

8 Responses

  1. Jeff Says:

    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…

  2. Nik Radford Says:

    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? :)

  3. Anonymous Says:

    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

  4. Gopinath Varadharajan Says:

    Hi,

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

    Thanks,

    Gopi

  5. Mikael Eliasson Says:

    Gopinath>>

    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.

  6. Tagnard Says:

    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/

  7. ahura mazda Says:

    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
    bitmapImage = new BitmapImage(); bitmapImage.SetSource(isolatedStorageFileStream);
    Image image = new Image();
    image.Source = bitmapImage;

  8. The Tallest Says:

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

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.

Powered by WP Hashcash