Reputation: 23
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
}
}
I tried to use to code below to get my contact's image from UWP. My problem is: I don't know how to get a BitMap from IRandomAccessStreamWithContentType
How can I get it?
Upvotes: 1
Views: 259
Reputation: 15758
When you say "BitMapImage", I'd suppose you mean BitmapImage Class used in UWP. If so, you can define a BitmapImage by calling SetSourceAsync and supplying a stream.
SetSourceAsync method needs a IRandomAccessStream as parameter and IRandomAccessStreamWithContentType Interface just inherits form IRandomAccessStream. So you can get a BitmapImage from RandomAccessStreamWithContentType easily like the following:
if (Mycontact.Thumbnail != null)
{
using (IRandomAccessStreamWithContentType stream = await Mycontact.Thumbnail.OpenReadAsync())
{
var bitmapimage = new BitmapImage();
await bitmapimage.SetSourceAsync(stream);
//TODO with bitmapimage
}
}
Upvotes: 1