【问题标题】:uwp StorageFile not getting a simple thumbnailuwp StorageFile 没有得到简单的缩略图
【发布时间】:2017-10-20 07:56:08
【问题描述】:

我在将图像缩略图数据绑定到 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() 方法返回一个 System.__ComObject,实际上它应该返回一个 IReadOnlyList&lt;StorageFile&gt;

【问题讨论】:

  • 调试您的应用程序并观察 System.UnauthorizedAccessException 的输出窗口
  • 我允许 VideoLibrary 来自 capibilities 所以没有例外

标签: c# image xaml thumbnails uwp-xaml


【解决方案1】:

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

我已经测试了您的代码,它适用于我。我必须启用 VideoLibrary 功能(如您所做的那样)并将视频放入我的视频文件夹中。

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-05
      • 1970-01-01
      • 2011-10-04
      • 1970-01-01
      • 1970-01-01
      • 2012-08-11
      • 2016-06-20
      • 1970-01-01
      相关资源
      最近更新 更多