Scenario
- App opens
- Checks to see if image for background exists in Isolated Storage
- If not, downloads from web, and saves it to Isolated Storage
- Loads the image from Isolated Storage and sets it as Background on a Panorama-control
Problem
The image is not loaded in GUI.. When I'm inspecting the byte-array received from isolated storage, it contains the same amount of bytes as was written initially, but the image doesn't show up.
Here's some test-code I'm currently using to try and figure out the problem:
using (IsolatedStorageFile appStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
if (!appStorage.FileExists(@"default.jpg"))
{
BitmapImage bmp = sender as BitmapImage;
byte[] bytes = bmp.ConvertToBytes();
using (var inputfile = appStorage.CreateFile(@"default.jpg"))
{
inputfile.Write(bytes, 0, bytes.Length);
}
}
using (var isfs = appStorage.OpenFile(@"default.jpg", FileMode.OpenOrCreate, FileAccess.Read))
{
BitmapImage bmp = new BitmapImage();
bmp.SetSource(isfs);
MainPanorama.Background = new ImageBrush { Opacity = 0.4, Stretch = Stretch.None, ImageSource = bmp };
}
}
Where sender
is a loaded image from some other source
I've tried setting the sender as backgroundimage on the MainPanorama-control, and that works just fine. So the problem is in the loading from Isolated Storage.
Any ideas?