private async void GetThumbnailButton_Click(object sender, RoutedEventArgs e) { rootPage.ResetOutput(ThumbnailImage, OutputTextBlock); // Pick a document FileOpenPicker openPicker = new FileOpenPicker(); foreach (string extension in FileExtensions.Document) { openPicker.FileTypeFilter.Add(extension); } StorageFile file = await openPicker.PickSingleFileAsync(); if (file != null) { const ThumbnailMode thumbnailMode = ThumbnailMode.DocumentsView; const uint size = 100; using (StorageItemThumbnail thumbnail = await file.GetThumbnailAsync(thumbnailMode, size)) { if (thumbnail != null) { MainPage.DisplayResult(ThumbnailImage, OutputTextBlock, thumbnailMode.ToString(), size, file, thumbnail, false); } else { rootPage.NotifyUser(Errors.NoIcon, NotifyType.StatusMessage); } } } else { rootPage.NotifyUser(Errors.Cancel, NotifyType.StatusMessage); } }
private async void GetThumbnailButton_Click(object sender, RoutedEventArgs e) { rootPage.ResetOutput(ThumbnailImage, OutputTextBlock); // Pick a folder FolderPicker folderPicker = new FolderPicker(); foreach (string extension in FileExtensions.Image) { folderPicker.FileTypeFilter.Add(extension); } StorageFolder folder = await folderPicker.PickSingleFolderAsync(); if (folder != null) { const ThumbnailMode thumbnailMode = ThumbnailMode.PicturesView; const uint size = 200; using (StorageItemThumbnail thumbnail = await folder.GetThumbnailAsync(thumbnailMode, size)) { if (thumbnail != null) { MainPage.DisplayResult(ThumbnailImage, OutputTextBlock, thumbnailMode.ToString(), size, folder, thumbnail, false); } else { rootPage.NotifyUser(Errors.NoImages, NotifyType.StatusMessage); } } } else { rootPage.NotifyUser(Errors.Cancel, NotifyType.StatusMessage); } }
private async void SelectImageButton_Click(object sender, RoutedEventArgs e) { rootPage.ResetOutput(ThumbnailImage, OutputTextBlock); uint size; if (uint.TryParse(RequestSize.Text, out size)) { // Pick a photo FileOpenPicker openPicker = new FileOpenPicker(); foreach (string extension in FileExtensions.Image) { openPicker.FileTypeFilter.Add(extension); } StorageFile file = await openPicker.PickSingleFileAsync(); if (file != null) { const ThumbnailMode thumbnailMode = ThumbnailMode.SingleItem; bool fastThumbnail = FastThumbnailCheckBox.IsChecked.Value; ThumbnailOptions thumbnailOptions = ThumbnailOptions.UseCurrentScale; if (fastThumbnail) { thumbnailOptions |= ThumbnailOptions.ReturnOnlyIfCached; } using (StorageItemThumbnail thumbnail = await file.GetScaledImageAsThumbnailAsync(thumbnailMode, size, thumbnailOptions)) { if (thumbnail != null) { MainPage.DisplayResult(ThumbnailImage, OutputTextBlock, thumbnailMode.ToString(), size, file, thumbnail, false); } else if (fastThumbnail) { rootPage.NotifyUser(Errors.NoExifThumbnail, NotifyType.StatusMessage); } else { rootPage.NotifyUser(Errors.NoThumbnail, NotifyType.StatusMessage); } } } else { rootPage.NotifyUser(Errors.Cancel, NotifyType.StatusMessage); } } else { rootPage.NotifyUser(Errors.InvalidSize, NotifyType.ErrorMessage); } }
private async void GetThumbnailButton_Click(object sender, RoutedEventArgs e) { rootPage.ResetOutput(ThumbnailImage, OutputTextBlock); // Pick a photo FileOpenPicker openPicker = new FileOpenPicker(); foreach (string extension in FileExtensions.Image) { openPicker.FileTypeFilter.Add(extension); } StorageFile file = await openPicker.PickSingleFileAsync(); if (file != null) { string thumbnailModeName = ((ComboBoxItem)ModeComboBox.SelectedItem).Name; ThumbnailMode thumbnailMode = (ThumbnailMode)Enum.Parse(typeof(ThumbnailMode), thumbnailModeName); bool fastThumbnail = FastThumbnailCheckBox.IsChecked.Value; ThumbnailOptions thumbnailOptions = ThumbnailOptions.UseCurrentScale; if (fastThumbnail) { thumbnailOptions |= ThumbnailOptions.ReturnOnlyIfCached; } const uint size = 200; using (StorageItemThumbnail thumbnail = await file.GetThumbnailAsync(thumbnailMode, size, thumbnailOptions)) { if (thumbnail != null) { MainPage.DisplayResult(ThumbnailImage, OutputTextBlock, thumbnailModeName, size, file, thumbnail, false); } else if (fastThumbnail) { rootPage.NotifyUser(Errors.NoExifThumbnail, NotifyType.StatusMessage); } else { rootPage.NotifyUser(Errors.NoThumbnail, NotifyType.StatusMessage); } } } else { rootPage.NotifyUser(Errors.Cancel, NotifyType.StatusMessage); } }
private async void GetThumbnailButton_Click(object sender, RoutedEventArgs e) { rootPage.ResetOutput(ThumbnailImage, OutputTextBlock); // Pick a music file FileOpenPicker openPicker = new FileOpenPicker(); foreach (string extension in FileExtensions.Music) { openPicker.FileTypeFilter.Add(extension); } StorageFile file = await openPicker.PickSingleFileAsync(); if (file != null) { const ThumbnailMode thumbnailMode = ThumbnailMode.MusicView; const uint size = 100; using (StorageItemThumbnail thumbnail = await file.GetThumbnailAsync(thumbnailMode, size)) { // Also verify the type is ThumbnailType.Image (album art) instead of ThumbnailType.Icon // (which may be returned as a fallback if the file does not provide album art) if (thumbnail != null && thumbnail.Type == ThumbnailType.Image) { // Display the thumbnail MainPage.DisplayResult(ThumbnailImage, OutputTextBlock, thumbnailMode.ToString(), size, file, thumbnail, false); } else { rootPage.NotifyUser(Errors.NoAlbumArt, NotifyType.StatusMessage); } } } else { rootPage.NotifyUser(Errors.Cancel, NotifyType.StatusMessage); } }
private async void GetThumbnailButton_Click(object sender, RoutedEventArgs e) { rootPage.ResetOutput(ThumbnailImage, OutputTextBlock, OutputDetails); // Pick a folder FolderPicker folderPicker = new FolderPicker(); foreach (string extension in FileExtensions.Image) { folderPicker.FileTypeFilter.Add(extension); } StorageFolder folder = await folderPicker.PickSingleFolderAsync(); if (folder != null) { const CommonFolderQuery monthShape = CommonFolderQuery.GroupByMonth; // Verify queries are supported because they are not supported in all picked locations. if (folder.IsCommonFolderQuerySupported(monthShape)) { // Convert folder to file group and query for items IReadOnlyList <StorageFolder> months = await folder.CreateFolderQuery(monthShape).GetFoldersAsync(); if (months != null && months.Count > 0) { const ThumbnailMode thumbnailMode = ThumbnailMode.PicturesView; const uint size = 200; StorageFolder firstMonth = months[0]; using (StorageItemThumbnail thumbnail = await firstMonth.GetThumbnailAsync(thumbnailMode, size)) { if (thumbnail != null) { MainPage.DisplayResult(ThumbnailImage, OutputTextBlock, thumbnailMode.ToString(), size, firstMonth, thumbnail, true); // Also display the hierarchy of the file group to better visualize where the thumbnail comes from IReadOnlyList <StorageFile> files = await firstMonth.GetFilesAsync(); if (files != null) { StringBuilder output = new StringBuilder("\nList of files in this group:\n\n"); foreach (StorageFile file in files) { output.AppendFormat("{0}\n", file.Name); } OutputDetails.Text = output.ToString(); } } else { rootPage.NotifyUser(Errors.NoImages, NotifyType.StatusMessage); } } } else { rootPage.NotifyUser(Errors.FileGroupEmpty, NotifyType.StatusMessage); } } else { rootPage.NotifyUser(Errors.FileGroupLocation, NotifyType.StatusMessage); } } else { rootPage.NotifyUser(Errors.Cancel, NotifyType.StatusMessage); } }