首页 > 解决方案 > 如何从我的文件夹中获取缩略图?

问题描述

我想知道如何使用 C# 在 UWP 中获取缩略图

我想在我的文件夹中获取图像文件(gif、jpg 等)的所有缩略图

我阅读了很多关于获取缩略图的代码,并参考了这个和其他示例

但我无法完全理解 Xaml 的过程

你能告诉我如何从我的图书馆文件夹中获取缩略图吗?

标签: c#xamluwpthumbnails

解决方案


一旦您通过用户选择访问文件夹后,您FolderPicker可以从系统中检索缩略图。你可以使用GetScaledImageAsThumbnailAsync()它。例如:

private async Task<BitmapImage> GetThumbnail(StorageFile file)
{
    if (file != null)
    {
        StorageItemThumbnail thumb = await file.GetScaledImageAsThumbnailAsync(ThumbnailMode.VideosView);
        if (thumb != null)
        {
            BitmapImage img = new BitmapImage();
            await img.SetSourceAsync(thumb);
            return img;
        }
    }
    return null;
}

推荐阅读