【发布时间】:2015-03-03 15:51:25
【问题描述】:
我正在尝试从 google talk 获取 Avatar。 我收到了来自 goole talk 服务器的数据包,例如:
<presence from="xxxxxxxxxxxxx@gmail.com/MessagingA3e8c9465" to="xxxxxxxxxx@gmail.com/Jabber.NetF5D1AB65">
<show>away</show>
<caps:c ver="1.1" node="http://www.android.com/gtalk/client/caps" xmlns:caps="http://jabber.org/protocol/caps" />
<x xmlns="vcard-temp:x:update">
<photo>6373f2ccdf12ef06292ca2257dc0bdc9aa1040c2</photo>
</x>
我认为'<photo>' 标签的十六进制值是联系人的头像(显示图像)。 (如果我错了,请纠正我。)
我将该值转换为字节[] 并使用以下代码显示图像。
pictureBox1.Image = Image.FromStream(new MemoryStream(byte_array));
// byte_array is byte[] converted from hex value.
它引发异常说:
参数无效。
我正在使用以下函数从十六进制转换为字节[]:
private static byte[] HexString2Bytes(string hexString)
{
int bytesCount = (hexString.Length) / 2;
byte[] bytes = new byte[bytesCount];
for (int x = 0; x < bytesCount; ++x)
{
bytes[x] = Convert.ToByte(hexString.Substring(x * 2, 2), 16);
}
return bytes;
}
我尝试了很多方法,但结果都一样。
我也尝试将十六进制值转换为大写,但没有运气,结果相同。
我在 Windows 8.1 机器上使用 .net 3.5。
谢谢
更新: 感谢大家的cmets和回答。
我错了十六进制值不是头像(显示图像)。
我向服务器发送了“iq”请求,它给出了头像。
非常感谢。 快乐编码。
【问题讨论】:
-
它看起来不像一些图像,只是因为它太短了——它只有 20 个字节。举个例子——典型的 16x16 像素 png 图像大约需要 800 字节。
-
虽然不是 C#,this 的答案有一些您可能会觉得有用的信息。
-
感谢@AndyKorneyev,这不是图片。
-
@SwDevMan81 感谢我知道 Delphi 的链接,该链接很有帮助。
标签: c# image winforms .net-3.5