StorageItemThumbnail StorageItemThumbnail StorageItemThumbnail StorageItemThumbnail Class

Represents the thumbnail image associated with a system resource (like a file or folder).

Syntax

Declaration

public sealed class StorageItemThumbnailpublic sealed class StorageItemThumbnailPublic NotInheritable Class StorageItemThumbnailpublic sealed class StorageItemThumbnail

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 GetThumbnailAsync(ThumbnailMode, UInt32) methods, or to get a thumbnail for a contact you can use the 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(ThumbnailMode, UInt32) 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 summary

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

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

Gets the MIME content type of the thumbnail image.

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

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

Gets the byte offset of the thumbnail stream.

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

Gets or sets the size of the thumbnail image.

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

Methods summary

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

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

Flushes data asynchronously in a sequential stream.

Retrieves the thumbnail image data as an undecoded stream.

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

Returns an asynchronous byte reader object.

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

Writes data asynchronously in a sequential stream.

Properties

  • CanRead
    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 boolpublic bool CanRead { get; }

    Property Value

    • bool
      bool
      bool
      bool

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

  • CanWrite
    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 boolpublic bool CanWrite { get; }

    Property Value

    • bool
      bool
      bool
      bool

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

  • ContentType
    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 stringpublic string ContentType { get; }

    Property Value

    • string
      string
      string
      string

      The MIME content type.

  • OriginalHeight
    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 uintpublic uint OriginalHeight { get; }

    Property Value

    • uint
      uint
      uint
      uint

      The original height, in pixels.

  • OriginalWidth
    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 uintpublic uint OriginalWidth { get; }

    Property Value

    • uint
      uint
      uint
      uint

      The original width, in pixels.

  • Position
    Position
    Position
    Position

    Gets the byte offset of the thumbnail stream.

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

    Property Value

    • ulong
      ulong
      ulong
      ulong

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

    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
    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 boolpublic bool ReturnedSmallerCachedSize { get; }

    Property Value

    • bool
      bool
      bool
      bool

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

  • Size
    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 ulongpublic ulong Size { get; set; }

    Property Value

    • ulong
      ulong
      ulong
      ulong

      The size, in bytes, of the thumbnail image.

  • Type
    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 ThumbnailTypepublic ThumbnailType Type { get; }

    Property Value

Methods

  • CloneStream()
    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 IRandomAccessStreampublic IRandomAccessStream CloneStream()

    Returns

  • Close()
    Close()
    Close()
    Close()

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

    public void Close()public void Close()Public Function Close() As voidpublic void Close()

    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.

  • FlushAsync()
    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 )public IAsyncOperation<bool> FlushAsync()

    Returns

    • The stream flush operation.

  • GetInputStreamAt(UInt64)
    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 IInputStreampublic IInputStream GetInputStreamAt(UInt64 position)

    Parameters

    • position
      System.UInt64
      System.UInt64
      System.UInt64
      System.UInt64

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

    Returns

  • GetOutputStreamAt(UInt64)
    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 IOutputStreampublic IOutputStream GetOutputStreamAt(UInt64 position)

    Parameters

    • position
      System.UInt64
      System.UInt64
      System.UInt64
      System.UInt64

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

    Returns

  • ReadAsync(IBuffer, UInt32, InputStreamOptions)
    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 )public IAsyncOperationWithProgress<IBuffer, uint> ReadAsync(IBuffer buffer, UInt32 count, InputStreamOptions options)

    Parameters

    Returns

    • The asynchronous operation.

  • Seek(UInt64)
    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 voidpublic void Seek(UInt64 position)

    Parameters

    • position
      System.UInt64
      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.

    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(IBuffer, UInt32, InputStreamOptions) and WriteAsync(IBuffer) methods will return error if they are called.

  • WriteAsync(IBuffer)
    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 )public IAsyncOperationWithProgress<uint, uint> WriteAsync(IBuffer buffer)

    Parameters

    Returns

    • The byte writer operation.

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)

Attributes

Windows.Foundation.Metadata.ContractVersionAttribute

Details

Assembly

Windows.Storage.FileProperties.dll