C# 如何将IrandoMacAccessStreamWithContentType转换为BitMapImage UWP?
我尝试使用下面的代码从UWP获取联系人的图像。我的问题是:我不知道如何从irandomaccesstreamwithcontenttype获取位图 我怎样才能得到它呢?当你说“位图图像”时,我想你的意思是在UWP中使用的。如果是这样,您可以通过调用并提供流来定义 方法需要一个as参数,接口只继承表单。因此,您可以通过以下方式轻松获得:C# 如何将IrandoMacAccessStreamWithContentType转换为BitMapImage UWP?,c#,uwp,C#,Uwp,我尝试使用下面的代码从UWP获取联系人的图像。我的问题是:我不知道如何从irandomaccesstreamwithcontenttype获取位图 我怎样才能得到它呢?当你说“位图图像”时,我想你的意思是在UWP中使用的。如果是这样,您可以通过调用并提供流来定义 方法需要一个as参数,接口只继承表单。因此,您可以通过以下方式轻松获得: var contactStore = await ContactManager.RequestStoreAsync(); Contact Mycontact =
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
}
}
请参考答案。可能的副本
if (Mycontact.Thumbnail != null)
{
using (IRandomAccessStreamWithContentType stream = await Mycontact.Thumbnail.OpenReadAsync())
{
var bitmapimage = new BitmapImage();
await bitmapimage.SetSourceAsync(stream);
//TODO with bitmapimage
}
}