:::: MENU ::::

Getting thumbnail from file in UWP app

In this post i will show how to extract thumbnail form file. For this post i wrote sample code for extracting thumbnail from images and display image of Song. So here are three simple step to perform the task.

Step 1:

Choose a file using normal FileOpenPicker class. Don’t forgot to add extensions of file.

Code:

Step 2:

If file is not null then use GetThumbnailAsync method to get thumbnail from that file. GetThumbnailAsync method takes couple of parameters and generate thumbnail based on those parameters.

Parameters are:

  • ThumbnailMode: Describes the purpose of the thumbnail to determine how to adjust the thumbnail image to retrieve. More here.
  • requestedSize: The requested size, in pixels, of the longest edge of the thumbnail. Windows uses the requestedSize as a guide and tries to scale the thumbnail image without reducing the quality of the image.
  • ThumbnailOptions: The enum value that describes the desired behavior to use to retrieve the thumbnail image. The specified behavior might affect the size and/or quality of the image and how quickly the thumbnail image is retrieved. More here.

When this method completes successfully, it returns a StorageItemThumbnail that represents the thumbnail image or null if there is no thumbnail image associated with the file.

Step 3:

Now we get thumbnail image lets convert that StorageItemThumbnail to BitmapImage and pass it to image element of our UI (From XAML) with additional information related to thumbnail. (I send additional info to know about generated thumbnail)

That’s it. Now you get thumbnail from your file/folder. In above code i get thumbnail form image file. In attached sample you can also find display image of song (Sample is on GitHub).

In action:

Happy Coding !!! 🙂