![](/img/trans.png)
[英]How can I change Skype user status from online to away using skype4com?
[英]How to display the skype user photo from HTTP Response using UCWA API?
我正在使用通用Windows應用程序,在當前項目中,我使用統一通信Web API(UCWA)來顯示skype用戶狀態,但工作正常,但是當我當時試圖顯示skype用戶照片時,我陷入了困境。
我點擊了以下鏈接以顯示照片https://msdn.microsoft.com/zh-cn/skype/ucwa/getmyphoto
對於GET請求,我得到了200 OK的響應代碼,但是我不知道如何從響應中顯示圖像。
請告訴我如何解決。
-Pradeep
我得到結果,獲得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;
您可以直接使用為用戶照片資源生成的URL。 只需將圖像的URL設置為“圖像”容器的源即可。 您的應用程序將自動加載它。
假設您放置了用於指定圖像類型的Accept標頭,則應該能夠查看Content-Length標頭來確定用戶在服務器上是否設置了圖像。 如果長度為零,則應考慮提供要顯示的默認圖像。 如果沒有,我建議您看一下UWP Platform中的“ 將位圖圖像轉換為字節數組”和“反之亦然”,因為您應該將響應主體視為一個字節數組,其長度由Content-Length標頭定義。
如果由於某種原因未提供Accept標頭,則響應主體不是image / *類型,並且看起來像一個字符串,則您可能正在處理Base64編碼的圖像。 這種情況下應該不太可能處理,但是如果您需要建議,我建議您在Windows Runtime中閱讀讀寫Base64 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.