2016-09-20 20 views
0

我正在使用通用Windows應用程序,在我當前的項目中,我使用了統一通信Web API(UCWA)來顯示Skype用戶狀態,但它正常工作,但是當我試圖顯示當時的Skype用戶照片時,我卡住了。如何使用UCWA API從HTTP響應中顯示Skype用戶照片?

我也跟着下面的鏈接顯示照片 https://msdn.microsoft.com/en-us/skype/ucwa/getmyphoto

我得到的200 OK我的GET請求響應代碼,但我不知道如何從我的反應顯示圖像。

請告訴我如何解決它。

-Pradeep

回答

1

我得到了結果,獲得HTTP響應後,我將這些響應內容轉換爲流類型通過使用下面這一行。

var presenceJsonStr = await httpResponseMessage.Content.ReadAsStreamAsync(); 

這是顯示圖像

var photo = await AuthenticationHelper.Photo(); 
// Create a .NET memory stream. 
       var memStream = new MemoryStream(); 

       // Convert the stream to the memory stream, because a memory stream supports seeking. 
       await photo.CopyToAsync(memStream); 

       // Set the start position. 
       memStream.Position = 0; 

       // Create a new bitmap image. 
       var bitmap = new BitmapImage(); 

       // Set the bitmap source to the stream, which is converted to a IRandomAccessStream. 
       bitmap.SetSource(memStream.AsRandomAccessStream()); 

       // Set the image control source to the bitmap. 
       imagePreivew.ImageSource = bitmap; 
0

假設你把一個接受頭指定圖像類型,你應該能夠看的Content-Length頭,以確定用戶是否在服務器上設置的圖像。如果長度爲零,則應考慮提供要顯示的默認圖像。如果沒有,我建議看看Convert a Bitmapimage into a Byte Array and Vice Versa in UWP Platform,因爲您應該將響應主體視爲一個字節數組,其長度由Content-Length標頭定義。

如果由於某種原因沒有提供Accept頭,響應體不是圖像/ *類型,並且看起來像一個字符串,那麼您可能正在處理Base64編碼圖像。這種情況應該不太可能處理,但如果您需要建議,我建議您查看Reading and Writing Base64 in the Windows Runtime

1

您可以直接使用用戶的照片資源產生的URL的代碼。只需將圖像的URL設置爲Image容器的來源即可。你的應用程序會自動加載它。

相關問題