Question

How do I get the image associated to a specific file (not thumbnail) in WinRT Apps?

Was it helpful?

Solution 2

This solution I found yesterday, too. But with ThumbnailMode.Music you get the Icon with the backgroundcolor of the app.

Finally I found, that with ThumbnailMode.SingleItem I get a better result without background. So first I create an empty file with the right file extension and then I try to get the thumbnail:

string filename = "_tmp_ext" + fileextension;
Windows.Storage.StorageFile file = 
  await ApplicationData.Current.TemporaryFolder.CreateFileAsync(
    filename, CreationCollisionOption.OpenIfExists);
FileProperties.StorageItemThumbnail thumb = 
  await file.GetThumbnailAsync(FileProperties.ThumbnailMode.SingleItem, 
    16, FileProperties.ThumbnailOptions.ResizeThumbnail);
if (thumb != null) {
  BitmapImage bitmapImage = new BitmapImage();
  bitmapImage.SetSource(thumb.CloneStream());
  /* ... */
}

Any other solutions without creating a dummy file?

OTHER TIPS

Looking at the Guidelines for thumbnails it seems like ThumbnailMode.Music might give you an icon when used with StorageFile.GetThumbnailAsync() for most file types - except music files that have an associated album art, although I'd hope to see a more robust way to get just the icon. Various MSDN Forums threads seem to indicate though that GetThumbnailAsync() IS the way to go.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top