Reputation: 9242
I am trying to get images from photo library of windows phone 8..and for the first time it is working fine. i get the image from Camera Roll folder for first time but when i tried to take the pictures from album Saved Picture it throws the Out Of Memory Exception.. i am not getting why is this happening. Any help is appreciated.
MediaImage mediaImage = new MediaImage();
BitmapImage image;
private void Panorama_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
{
Panorama obj = sender as Panorama;
PanoramaItem objPanoramaItem = (PanoramaItem)obj.SelectedItem;
string FolderName = objPanoramaItem.Header.ToString();
PictureAlbum AlbumFolder = allAlbums.Where(album => album.Name == FolderName).FirstOrDefault();
if (FolderName == "Camera Roll")
{
if (ImageListCameraRoll == null)
{
ImageListCameraRoll = new ObservableCollection<MediaImage>();
var CameraRollPictures = AlbumFolder.Pictures;
foreach (var picture in CameraRollPictures)
{
mediaImage = new MediaImage();
image = new BitmapImage();
image.SetSource(picture.GetImage());
mediaImage.ImageFile = image;
mediaImage.ImageName = picture.Name;
ImageListCameraRoll.Add(mediaImage);
}
}
ListboxCameraRoll.ItemsSource = ImageListCameraRoll;
}
if (FolderName == "Saved Pictures1")
{
if (ImageListSavedPictures == null)
{
ImageListSavedPictures = new ObservableCollection<MediaImage>();
var SavedPictures = AlbumFolder.Pictures;
foreach (var picture in SavedPictures)
{
mediaImage = new MediaImage();
image = new BitmapImage();
image.SetSource(picture.GetImage());
mediaImage.ImageFile = image;
mediaImage.ImageName = picture.Name;
ImageListSavedPictures.Add(mediaImage);
}
}
ListboxSavedPictures.ItemsSource = ImageListSavedPictures;
}
}
what i am doing here is trying to get the pictures on panorama item changed event. Panorama item is based on different folders in photo library..
Upvotes: 0
Views: 1203
Reputation: 180887
Loading all images from a folder into memory may take a lot of memory space. Unless you really need the full size images, I'd suggest using GetThumbnail() instead to load low resolution versions of the photos. You can always go back to the originals once the user has selected which photos to perform an action on.
image.SetSource(picture.GetThumbnail());
Upvotes: 5