[英]How can I convert IRandomAccessStreamWithContentType to BitMapImage UWP?
var contactStore = await ContactManager.RequestStoreAsync();
Contact Mycontact = await contactStore.GetContactAsync(contact.Id);
if (Mycontact.Thumbnail != null)
{
using (IRandomAccessStreamWithContentType stream = await Mycontact.Thumbnail.OpenReadAsync())
{
// todo: get bitmapimage
}
}
我嘗試使用下面的代碼從UWP獲取聯系人的圖像。 我的問題是:我不知道如何從IRandomAccessStreamWithContentType獲取BitMap
我怎么才能得到它?
當您說“ BitMapImage”時,我想您是指UWP中使用的BitmapImage 類 。 如果是這樣,則可以通過調用SetSourceAsync並提供流來定義BitmapImage 。
SetSourceAsync方法需要使用IRandomAccessStream作為參數,而帶有ContentType 類型接口的IandomAccessStream僅繼承IRandomAccessStream的形式。 因此您可以輕松地從帶有內容類型的Random Access Stream中獲取BitmapImage ,如下所示:
if (Mycontact.Thumbnail != null)
{
using (IRandomAccessStreamWithContentType stream = await Mycontact.Thumbnail.OpenReadAsync())
{
var bitmapimage = new BitmapImage();
await bitmapimage.SetSourceAsync(stream);
//TODO with bitmapimage
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.