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, IRandomAccessStreamWithContentTypepublic sealed class StorageItemThumbnail : IDisposable, IThumbnailProperties, IContentTypeProvider, IInputStream, IOutputStream, IRandomAccessStream, IRandomAccessStreamWithContentTypePublic NotInheritable Class StorageItemThumbnail Implements IDisposable, IThumbnailProperties, IContentTypeProvider, IInputStream, IOutputStream, IRandomAccessStream, IRandomAccessStreamWithContentType
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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.

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).

Properties

CanRead CanRead CanRead

Gets a value that indicates whether the thumbnail stream can be read from.

public bool CanRead { get; }public bool CanRead { get; }Public ReadOnly Property CanRead As bool
Value
bool bool bool

True if the thumbnail stream can be read from. Otherwise, false.

Attributes

CanWrite CanWrite CanWrite

Gets a value that indicates whether the thumbnail stream can be written to.

public bool CanWrite { get; }public bool CanWrite { get; }Public ReadOnly Property CanWrite As bool
Value
bool bool bool

True if the thumbnail stream can be written to. Otherwise, false.

Attributes

ContentType ContentType ContentType

Gets the MIME content type of the thumbnail image.

public string ContentType { get; }public string ContentType { get; }Public ReadOnly Property ContentType As string
Value
string string string

The MIME content type.

Attributes

OriginalHeight OriginalHeight OriginalHeight

Gets the original (not scaled) height of the thumbnail image.

public uint OriginalHeight { get; }public uint OriginalHeight { get; }Public ReadOnly Property OriginalHeight As uint
Value
uint uint uint

The original height, in pixels.

Attributes

OriginalWidth OriginalWidth OriginalWidth

Gets the original (not scaled) width of the thumbnail image.

public uint OriginalWidth { get; }public uint OriginalWidth { get; }Public ReadOnly Property OriginalWidth As uint
Value
uint uint uint

The original width, in pixels.

Attributes

Position Position Position

Gets the byte offset of the thumbnail stream.

public ulong Position { get; }public ulong Position { get; }Public ReadOnly Property Position As ulong
Value
ulong ulong ulong

The number of bytes from the start of the thumbnail stream.

Attributes

Remarks

The initial offset of a thumbnail stream is 0.

The offset of the thumbnail stream is changed by both read and write operations.

ReturnedSmallerCachedSize ReturnedSmallerCachedSize ReturnedSmallerCachedSize

Gets a value that indicates whether the thumbnail image returned was a cached version with a smaller size.

public bool ReturnedSmallerCachedSize { get; }public bool ReturnedSmallerCachedSize { get; }Public ReadOnly Property ReturnedSmallerCachedSize As bool
Value
bool bool bool

The value that indicates whether the thumbnail image returned was a cached version with a smaller size.

Attributes

Size Size Size

Gets or sets the size of the thumbnail image.

public ulong Size { get; set; }public ulong Size { get; set; }Public ReadWrite Property Size As ulong
Value
ulong ulong ulong

The size, in bytes, of the thumbnail image.

Attributes

Type Type Type

Gets a value that indicates if the thumbnail is an icon or an image.

public ThumbnailType Type { get; }public ThumbnailType Type { get; }Public ReadOnly Property Type As ThumbnailType
Value
ThumbnailType ThumbnailType ThumbnailType

The value that indicates if the thumbnail is an icon or an image.

Attributes

Methods

CloneStream() CloneStream() CloneStream()

Creates a new stream over the thumbnail that is represented by the current storageItemThumbnail object.

public IRandomAccessStream CloneStream()public IRandomAccessStream CloneStream()Public Function CloneStream() As IRandomAccessStream
Returns

The new thumbnail stream. The initial, internal position of the stream is 0.

The internal position and lifetime of this new thumbnail stream are independent from the position and lifetime of the cloned stream.

Attributes

Close() Close() Close()

Releases system resources that are exposed by a Windows Runtime object.

public void Close()This member is not implemented in C#This member is not implemented in VB.Net
Attributes

Remarks

Use this method to release the exclusive system resources that are in use, such as file handles, streams, and network sockets. The method should also release other resources that are in use, including object references and memory, to prepare them for reuse.

This method must call the Close method of any object it holds that implements IClosable.

The Close method should release system resources as quickly as possible, without blocking for asynchronous operations to complete. To ensure that all resources are completely released, the caller must wait for all outstanding asynchronous operations to complete before calling Close.

After Close returns, the object is still in memory but without the system resources it needs; therefore, most of its members are not usable. A member that depends on a released system resource can return RO_E_CLOSED to indicate that the object is closed and it cannot complete the requested operation.

If you call Close multiple times, there is no effect; the method returns S_OK.

Dispose() Dispose() Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

This member is not implemented in C++void Dispose()Sub Dispose
Attributes

FlushAsync() FlushAsync() FlushAsync()

Flushes data asynchronously in a sequential stream.

public IAsyncOperation<bool> FlushAsync()public IAsyncOperation<bool> FlushAsync()Public Function FlushAsync() As IAsyncOperation( Of bool )
Returns

The stream flush operation.

Attributes

GetInputStreamAt(UInt64) GetInputStreamAt(UInt64) GetInputStreamAt(UInt64)

Retrieves the thumbnail image data as an undecoded stream.

public IInputStream GetInputStreamAt(UInt64 position)public IInputStream GetInputStreamAt(UInt64 position)Public Function GetInputStreamAt(position As UInt64) As IInputStream
Parameters
position
System.UInt64 System.UInt64 System.UInt64

The position in the storage item to start reading thumbnail image data.

Returns

An object for reading the thumbnail image data.

Attributes

GetOutputStreamAt(UInt64) GetOutputStreamAt(UInt64) GetOutputStreamAt(UInt64)

Retrieves an output stream object for writing thumbnail image data to a storage item.

public IOutputStream GetOutputStreamAt(UInt64 position)public IOutputStream GetOutputStreamAt(UInt64 position)Public Function GetOutputStreamAt(position As UInt64) As IOutputStream
Parameters
position
System.UInt64 System.UInt64 System.UInt64

The position in the storage item to start writing thumbnail image data.

Returns
Attributes

ReadAsync(IBuffer, UInt32, InputStreamOptions) ReadAsync(IBuffer, UInt32, InputStreamOptions) ReadAsync(IBuffer, UInt32, InputStreamOptions)

Returns an asynchronous byte reader object.

public IAsyncOperationWithProgress<IBuffer, uint> ReadAsync(IBuffer buffer, UInt32 count, InputStreamOptions options)public IAsyncOperationWithProgress<IBuffer, uint> ReadAsync(IBuffer buffer, UInt32 count, InputStreamOptions options)Public Function ReadAsync(buffer As IBuffer, count As UInt32, options As InputStreamOptions) As IAsyncOperationWithProgress( Of IBuffer, uint )
Parameters
buffer
IBuffer IBuffer IBuffer

The buffer into which the asynchronous read operation places the bytes that are read.

count
System.UInt32 System.UInt32 System.UInt32

The number of bytes to read that is less than or equal to the Capacity value.

options
InputStreamOptions InputStreamOptions InputStreamOptions

Specifies the type of the asynchronous read operation.

Returns

The asynchronous operation.

Attributes

Seek(UInt64) Seek(UInt64) Seek(UInt64)

Sets the offset of the thumbnail stream to the specified value.

public void Seek(UInt64 position)public void Seek(UInt64 position)Public Function Seek(position As UInt64) As void
Parameters
position
System.UInt64 System.UInt64 System.UInt64

The number of bytes from the start of the thumbnail stream where the position of the thumbnail stream is set.

Attributes

Remarks

Warning

This method does not check position to make sure the value is valid. If the value is invalid for the stream, the readAsync and writeAsync methods will return error if they are called.

WriteAsync(IBuffer) WriteAsync(IBuffer) WriteAsync(IBuffer)

Writes data asynchronously in a sequential stream.

public IAsyncOperationWithProgress<uint, uint> WriteAsync(IBuffer buffer)public IAsyncOperationWithProgress<uint, uint> WriteAsync(IBuffer buffer)Public Function WriteAsync(buffer As IBuffer) As IAsyncOperationWithProgress( Of uint, uint )
Parameters
buffer
IBuffer IBuffer IBuffer

The buffer into which the asynchronous writer operation writes.

Returns

The byte writer operation.

Attributes

See Also