2017-05-27 6 views
0
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から取得するために以下のコードを使用しようとしました。私の問題は次のとおりです。BitMapを入手する方法がわからないIRandomAccessStreamWithContentTypeIRandomAccessStreamWithContentTypeをBitMapImage UWPに変換するにはどうすればよいですか?

どうすれば入手できますか?

+0

[この](https://stackoverflow.com/questions/15328084/convert-irandomaccessstreamwithcontenttype-to-byte)の回答を参照してください。 – CodingYoshi

+0

[IRandomAccessStreamWithContentTypeをByte \ [\]]に変換する可能性のある複製(https://stackoverflow.com/questions/15328084/convert-irandomaccessstreamwithcontenttype-to-byte) – Razor

答えて

0

「BitMapImage」と言えば、UWPでBitmap​Image Classが使用されているとします。その場合は、SetSourceAsyncを呼び出してストリームを提供することによってBitmapImageを定義することができます。

SetSourceAsyncメソッドは、パラメータとしてIRandomAccessStreamを必要とし、I​Random​Access​Stream​With​Content​TypeインターフェイスはフォームIRandomAccessStreamをちょうど継承します。だから、次のように簡単にRandom​Access​Stream​With​Content​TypeからBitmapImageを取得することができます。

if (Mycontact.Thumbnail != null) 
{ 
    using (IRandomAccessStreamWithContentType stream = await Mycontact.Thumbnail.OpenReadAsync()) 
    { 
     var bitmapimage = new BitmapImage(); 
     await bitmapimage.SetSourceAsync(stream); 
     //TODO with bitmapimage 
    } 
} 
関連する問題