uwp StorageFile 没有得到一个简单的缩略图

uwp StorageFile not getting a simple thumbnail

我在将图像缩略图数据绑定到 xaml 上的图像时遇到了一些问题,所以我做了一个简单的示例来向您展示我想要获得的只是来自一个文件的简单缩略图并显示它到 xaml.

上的图像元素

我在过去的 uwp 应用程序中处理过很多缩略图,我不明白我在这里做错了什么。

C#代码

 public sealed partial class MainPage : Page
{
    public MainPage()
    {
        this.InitializeComponent();
    }
    protected async override void OnNavigatedTo(NavigationEventArgs e)
    {
        img.Source = await GetIt();
    }
    public async Task<BitmapImage> GetIt()
    {
        var files=await KnownFolders.VideosLibrary.GetFilesAsync();
        var thumb=await files[0].GetThumbnailAsync(Windows.Storage.FileProperties.ThumbnailMode.VideosView);
        var bitm = new BitmapImage();
        bitm.SetSource(thumb);
        return bitm;
    }
}

XAML 代码

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Image Name="img"/>
</Grid>

输出只是一张空白的白页

注意 我试过在 return bitm 上设置断点,但此断点从未执行。我还注意到 GetAllFiles() 方法 return a System.__ComObject 实际上它应该 return a IReadOnlyList<StorageFile>.

您确定文件集合不为空吗?

我已经测试了你的代码,它对我有用。我必须启用 VideoLibrary 功能(就像您所做的那样)并将视频放入我的视频文件夹。

只是内存问题;奇怪 Visual Studio 没有认出它,我刚刚重新启动笔记本电脑,缩略图开始出现。