StorageItemThumbnail
StorageItemThumbnail
StorageItemThumbnail
StorageItemThumbnail
StorageItemThumbnail
Class
Definition
Represents the thumbnail image associated with a system resource (like a file or folder).
public : sealed class StorageItemThumbnail : IClosable, IThumbnailProperties, IContentTypeProvider, IInputStream, IOutputStream, IRandomAccessStream, IRandomAccessStreamWithContentType
struct winrt::Windows::Storage::FileProperties::StorageItemThumbnail : IClosable, IThumbnailProperties, IContentTypeProvider, IInputStream, IOutputStream, IRandomAccessStream, IRandomAccessStreamWithContentType
public sealed class StorageItemThumbnail : IDisposable, IThumbnailProperties, IContentTypeProvider, IInputStream, IOutputStream, IRandomAccessStream, IRandomAccessStreamWithContentType
Public NotInheritable Class StorageItemThumbnail Implements IDisposable, IThumbnailProperties, IContentTypeProvider, IInputStream, IOutputStream, IRandomAccessStream, IRandomAccessStreamWithContentType
// This class does not provide a public constructor.
- Attributes
Device family |
Windows 10 (introduced v10.0.10240.0)
|
API contract |
Windows.Foundation.UniversalApiContract (introduced v1)
|
Examples
This example demonstrates how to get thumbnails for files.
// Set query options with filter and sort order for results
List<string> fileTypeFilter = new List<string>();
fileTypeFilter.Add(".jpg");
fileTypeFilter.Add(".png");
fileTypeFilter.Add(".bmp");
fileTypeFilter.Add(".gif");
var queryOptions = new QueryOptions(CommonFileQuery.OrderByName, fileTypeFilter);
// Create query and retrieve files.
var query = KnownFolders.PicturesLibrary.CreateFileQueryWithOptions(queryOptions);
IReadOnlyList<StorageFile> fileList = await query.GetFilesAsync();
// Process results
foreach (StorageFile file in fileList)
{
// Get thumbnail
const uint requestedSize = 190;
const ThumbnailMode thumbnailMode = ThumbnailMode.PicturesView;
const ThumbnailOptions thumbnailOptions = ThumbnailOptions.UseCurrentScale;
var thumbnail = await file.GetThumbnailAsync(thumbnailMode, requestedSize, thumbnailOptions);
}
// Set query options with filter and sort order for results
var fileTypeFilter = [".jpg", ".png", ".bmp", ".gif"];
var queryOptions = new Windows.Storage.Search.QueryOptions(search.CommonFileQuery.orderByName, fileTypeFilter);
// Create query and retrieve files
var query = Windows.Storage.KnownFolders.picturesLibrary.createFileQueryWithOptions(queryOptions);
query.getFilesAsync().done(function (files) {
// Process results
files.forEach(function (file) {
// Get thumbnail
var requestedSize = 190;
var thumbnailMode = Windows.Storage.FileProperties.ThumbnailMode.picturesView;
var thumbnailOptions = Windows.Storage.FileProperties.ThumbnailOptions.useCurrentScale;
item.getThumbnailAsync(thumbnailMode, requestedSize, thumbnailOptions).done(function (thumbnail) {
// Perform tasks with thumnail
});
});
});
After GetThumbnailAsync completes, thumbnail gets a StorageItemThumbnail object.
In the example, the file
variable gets a StorageFile that represents each file that we want to retrieve a thumbnail for. We used a query to obtain StorageFile objects for these files (stored in the file
variable), but you can use whatever approach is best for your app to obtain StorageFile objects (like through the file picker).
Remarks
You can get thumbnails for many file system resources through the Windows Runtime objects that represent them. Many of these objects have methods or properties that let you get (and sometimes set) a StorageItemThumbnail that represents the thumbnail associated with a particular resource.
To find out how to get thumbnail for a particular Windows Runtime object, see the documentation for that object. For example, to get a thumbnail for a file you can call one of the StorageFile.getThumbnailAsync methods, or to get a thumbnail for a contact you can use the Contact.thumbnail property.
For more code samples about retrieving thumbnails, see the Folder enumeration sample and the File thumbnails sample.
Properties
CanRead CanRead CanRead CanRead CanRead |
Gets a value that indicates whether the thumbnail stream can be read from. |
CanWrite CanWrite CanWrite CanWrite CanWrite |
Gets a value that indicates whether the thumbnail stream can be written to. |
ContentType ContentType ContentType ContentType ContentType |
Gets the MIME content type of the thumbnail image. |
OriginalHeight OriginalHeight OriginalHeight OriginalHeight OriginalHeight |
Gets the original (not scaled) height of the thumbnail image. |
OriginalWidth OriginalWidth OriginalWidth OriginalWidth OriginalWidth |
Gets the original (not scaled) width of the thumbnail image. |
Position Position Position Position Position |
Gets the byte offset of the thumbnail stream. |
ReturnedSmallerCachedSize ReturnedSmallerCachedSize ReturnedSmallerCachedSize ReturnedSmallerCachedSize ReturnedSmallerCachedSize |
Gets a value that indicates whether the thumbnail image returned was a cached version with a smaller size. |
Size Size Size Size Size |
Gets or sets the size of the thumbnail image. |
Type Type Type Type Type |
Gets a value that indicates if the thumbnail is an icon or an image. |