Exemplo n.º 1
0
        /// <summary>
        /// Asynchronously returns a list of all pictures in the specified album
        /// </summary>
        /// <param name="albumName">The name of the album</param>
        /// <param name="path">The path of the album</param>
        /// <returns>A list of all pictures in the specified album</returns>
        /// <remarks>The path parameter is not actually used in this Windows Phone implementation
        /// since the MediaLibrary API does not support picture or album retrieval with a path. Instead, we must walk
        /// the library looking for the album with the given albumName and then grab all the pictures in that album.</remarks>
        public Task<List<PictureViewModel>> GetPicturesAsync(string albumName, string path)
        {
            return Task.Run(delegate
            {
              List<PictureViewModel> result = new List<PictureViewModel>();
              MediaLibrary mediaLib = new MediaLibrary();

              // Find the album
              foreach (var album in mediaLib.RootPictureAlbum.Albums)
              {
                // Because the photo library API on Windows Phone doesn't expose the concept of "path",
                // we iterate and find the album based on the name.
                if (album.Name == albumName)
                {
                  foreach (var pic in album.Pictures)
                  {
                    PictureViewModel pvm = new PictureViewModel(App.PictureService, albumName, pic.Name,String.Format("{0}|{1}",albumName, pic.Name),pic.Width, pic.Height);
                    result.Add(pvm);
                  }
                  Debug.WriteLine("{0} pictures in {1}", result.Count(), albumName);
                  break;
                }
              }
              return result;
            });
        }
Exemplo n.º 2
0
        public async Task<List<PictureViewModel>> GetPicturesAsync(string albumName, string path)
        {
            List<PictureViewModel> result = new List<PictureViewModel>();
            StorageFolder folder;
            if (String.IsNullOrEmpty(path))
                folder = KnownFolders.PicturesLibrary;
            else
                folder = await StorageFolder.GetFolderFromPathAsync(path);
            var files = await folder.GetFilesAsync();

            foreach (var file in files)
            {
                var properties = await file.Properties.GetImagePropertiesAsync();

                PictureViewModel pvm = new PictureViewModel(App.PictureService,albumName, file.DisplayName, file.Path, (int)properties.Height, (int)properties.Width);
                result.Add(pvm);
            }

            return result;
        }