作为练习,我正在尝试将Overv/SteamWebAPI移植到可移植类库。但是,其中一个函数返回System.Drawing.Bitmap
.NET Portable 子集中不可用的 。
考虑到下面的功能,最好的选择是什么?由于项目的性质,我不关心向后兼容性。
有问题的功能:
/// <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;
}
}