3
作爲練習,我試圖將Overv/SteamWebAPI移植到可移植類庫中。但是,其中一個函數返回一個System.Drawing.Bitmap
,這在.NET Portable子集中不可用。.NET Portable Framework中的System.Drawing.Bitmap
考慮到下面的功能,最好的選擇是什麼?由於該項目的性質,我不關心後向兼容性問題。
有問題的功能:
/// <summary>
/// Retrieve the avatar of the specified user in the specified format.
/// </summary>
/// <param name="user">User</param>
/// <param name="size">Requested avatar size</param>
/// <returns>The avatar as bitmap on success or null on failure.</returns>
public Bitmap GetUserAvatar(User user, AvatarSize size = AvatarSize.Small)
{
if (user.avatarUrl.Length == 0) return null;
try
{
WebClient client = new WebClient();
Stream stream;
if (size == AvatarSize.Small)
stream = client.OpenRead(user.avatarUrl + ".jpg");
else if (size == AvatarSize.Medium)
stream = client.OpenRead(user.avatarUrl + "_medium.jpg");
else
stream = client.OpenRead(user.avatarUrl + "_full.jpg");
Bitmap avatar = new Bitmap(stream);
stream.Flush();
stream.Close();
return avatar;
}
catch (Exception e)
{
return null;
}
}
但要小心:'System.Windows.Media.Imaging.BitmapSource'在線程中播放效果並不好。 – vines 2017-09-06 11:34:00