Storing photos in isolated storage and reading mutiple photos with out memory consumption
I am storing photos of the users in Isolated storage and displaying them in a listbox. I used following code to retrieve image from isolated storage
BitmapImage bi = new BitmapImage();
var isoFile = Isolated开发者_Go百科StorageFile.GetUserStoreForApplication();
if (isoFile.FileExists(imageFileName))
{
using (var imageStream = isoFile.OpenFile(
imageFileName,
FileMode.Open, FileAccess.Read))
{
//imageSource = PictureDecoder.DecodeJpeg(imageStream);
bi.SetSource(imageStream);
}
}
isoFile.Dispose();
//return imageSource;
return bi;
There are 100 of images stored.Everytime the images are loaded, it the memory consumption keeps increasing and then runs out of memory.Is there any better way to access images with less memory consumption. I used GC.Collect()
even at the end of loading. It simply not working.
Is there a better way of stroing and reading images from the isolated storage ?
I let my users to save photos on the isolated storage. Is isolated storage a better option in my case ?
Stefan Wick has some great tips on working with images, including how to avoid undue memory consumption, on his blog at http://blogs.msdn.com/b/swick/archive/2011/04/07/image-tips-for-windows-phone-7.aspx
You just need to forcibly set the Image and internal BitmapImage to null
to release the memory when you're done with the image.
BitmapImage bitmapImage = image.Source as BitmapImage;
bitmapImage.UriSource = null;
image.Source = null;
精彩评论