public interface IDesktopThumbnails Thumbnails of files as the desktop's file manager shows them: the freedesktop.org thumbnail cache on Linux, the shell's thumbnail providers on Windows and Quick Look on macOS.
Remarks
A path is a fully qualified local path, supplied by trusted C# application code, never directly by a web client. The thumbnail is a PNG image, which a web view shows directly, for example as a data:image/png URL.
Outcomes common to every platform: a thumbnail is Success with a DesktopThumbnail; a file without one, such as a type no thumbnailer handles, a file whose thumbnailing failed or, on Linux, a desktop that runs no thumbnailer and has none cached, is Success with null; a path that does not exist is PlatformFailureCode.NotFound; access refused is PlatformFailureCode.PermissionDenied. An icon is never returned instead of a thumbnail.
Methods
GetThumbnailAsync
ValueTask<PlatformResult<DesktopThumbnail?>> GetThumbnailAsync(string path, int size, CancellationToken cancellationToken = default) Gets a thumbnail of the file at path for display at size pixels.
Parameters
pathA fully qualified local path.
sizeThe largest edge to display, from 1 to
DesktopThumbnails.MaximumSizepixels. The thumbnail keeps the file's aspect ratio and can differ in size: Linux returns the smallest cached size at least as large (128, 256, 512 or 1024 pixels), else the largest smaller one; Windows and macOS return at mostsizepixels, fewer for a small image.DesktopThumbnail.WidthandDesktopThumbnail.Heightreport the image's own size; scale it to display.cancellationTokenCancels the request, also while a thumbnailer generates the thumbnail.
Exceptions
ArgumentExceptionpathis empty, relative, contains NUL or names a root directory.ArgumentOutOfRangeExceptionsizeis less than 1 or greater thanDesktopThumbnails.MaximumSize.
GetThumbnailAsync
ValueTask<PlatformResult<DesktopThumbnail?>> GetThumbnailAsync(string path, int size, int scale, CancellationToken cancellationToken) Gets a thumbnail of the file at path for display at size pixels on a display with scale device pixels per pixel, such as a window's device pixel ratio.
Parameters
pathA fully qualified local path.
sizeThe largest edge to display, from 1 to
DesktopThumbnails.MaximumSizepixels at scale 1.scaleThe display scale, from 1 to
DesktopThumbnails.MaximumScale; 2 asks for an image with twice the pixels along each edge. The request issizetimesscaledevice pixels, at mostDesktopThumbnails.MaximumSize; the thumbnail is then sized asIDesktopThumbnails.GetThumbnailAsyncdescribes, in device pixels.cancellationTokenCancels the request, also while a thumbnailer generates the thumbnail.
Exceptions
ArgumentExceptionpathis empty, relative, contains NUL or names a root directory.ArgumentOutOfRangeExceptionsizeorscaleis outside its range.
Remarks
The token is required so that a call with three arguments, such as GetThumbnailAsync(path, 256, default), keeps binding to the overload without a scale. The default implementation asks IDesktopThumbnails.GetThumbnailAsync for the device-pixel size, which is what every Runic provider does.