我正在尝试从 Windows Phone 8 的照片库中获取图像。它第一次运行良好。我第一次从相机胶卷文件夹中获取图像,但是当我尝试从相册保存的图片中拍摄照片时,它会抛出内存不足异常。我不明白为什么会发生这种情况。任何帮助表示赞赏。
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;
}
}
我在这里做的是试图获取全景项目更改事件的图片。全景项目基于照片库中的不同文件夹。