【问题标题】:WinRT: Extract the Icon Associated with a File?WinRT:提取与文件关联的图标?
【发布时间】:2014-09-22 03:53:49
【问题描述】:

如何在 WinRT 应用程序中获取与特定文件(不是缩略图)关联的图像?

【问题讨论】:

    标签: c# windows-runtime icons thumbnails uwp


    【解决方案1】:

    查看Guidelines for thumbnails,对于大多数文件类型,ThumbnailMode.MusicStorageFile.GetThumbnailAsync() 一起使用时可能会给您一个图标 - 除了具有相关专辑封面的音乐文件,尽管我希望看到更多获取图标的可靠方法。各种 MSDN 论坛主题似乎表明 GetThumbnailAsync() 是要走的路。

    【讨论】:

      【解决方案2】:

      我昨天也找到了这个解决方案。但是使用ThumbnailMode.Music,您将获得带有应用背景颜色的图标。

      最后我发现,使用ThumbnailMode.SingleItem 可以在没有背景的情况下获得更好的结果。所以首先我创建了一个具有正确文件扩展名的空文件,然后我尝试获取缩略图:

      string filename = "_tmp_ext" + fileextension;
      Windows.Storage.StorageFile file = 
        await ApplicationData.Current.TemporaryFolder.CreateFileAsync(
          filename, CreationCollisionOption.OpenIfExists);
      FileProperties.StorageItemThumbnail thumb = 
        await file.GetThumbnailAsync(FileProperties.ThumbnailMode.SingleItem, 
          16, FileProperties.ThumbnailOptions.ResizeThumbnail);
      if (thumb != null) {
        BitmapImage bitmapImage = new BitmapImage();
        bitmapImage.SetSource(thumb.CloneStream());
        /* ... */
      }
      

      任何其他不创建虚拟文件的解决方案?

      【讨论】:

      • 您还可以查看此问题的最佳答案。它需要对 shell API 进行 p/invoke,但谁知道 - 也许它会起作用? stackoverflow.com/questions/616718/…
      • 这仅适用于没有 App-Certification 的 Side-Loading-Applications。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-07-03
      • 1970-01-01
      • 1970-01-01
      • 2012-03-21
      • 1970-01-01
      • 1970-01-01
      • 2019-07-23
      相关资源
      最近更新 更多