[英]C# converting UWP BitmapImage to WPF BitmapImage
我目前有一個WPF應用程序,在其中嘗試列出計算機上安裝的所有UWP應用程序的所有圖標。 為此,我引用了所需的UWP程序集。 這是我的工作:
PackageManager
。 FindPackagesForUser(string.Empty)
給我安裝的所有UWP應用。 package.GetAppListEntriesAsync()
獲得其所有列表條目。 appListEntry.DisplayInfo.GetLogo(new Size(256, 256))
。 但是,這將返回RandomAccessStreamReference
,它是Windows.UI.Xaml.Media.Imaging.BitmapImage
的UWP流,而UWP流又是WPF System.Windows.Media.Imaging.BitmapImage
的UWP版本。
如何將該流的字節轉換為WPF BitmapImage? 是否有關於UWP如何存儲這些文件的文檔?
只需打開RandomAccessStreamReference進行讀取即可獲取IRandomAccessStream
,然后調用AsStream
可以獲取System.IO.Stream
:
using System.IO;
...
var streamRef = appListEntry.DisplayInfo.GetLogo(new Windows.Foundation.Size(256, 256));
var bitmap = new BitmapImage();
using (var randomAccessStream = await streamRef.OpenReadAsync())
using (var stream = randomAccessStream.AsStream())
{
bitmap.BeginInit();
bitmap.CacheOption = BitmapCacheOption.OnLoad;
bitmap.StreamSource = stream;
bitmap.EndInit();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.