How do I get the image associated to a specific file (not thumbnail) in WinRT Apps?
Asked
Active
Viewed 861 times
2 Answers
4
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.

Filip Skakun
- 31,624
- 6
- 74
- 100
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?

dschüsä
- 657
- 5
- 16
-
You could also check the best answer to this question. It requires p/invoke to the shell APIs, but who knows - maybe it'd work? http://stackoverflow.com/questions/616718/how-do-i-get-common-file-type-icons-in-c – Filip Skakun Jul 31 '14 at 12:48
-
1This will only work for Side-Loading-Applications without App-Certification. – dschüsä Sep 04 '14 at 11:36