【发布时间】:2011-03-10 19:47:06
【问题描述】:
这个问题与Iphone SDK、NSData和UIImage有关。
我正在尝试从 xmpp 返回的头像数据创建图像,如下所示:
<presence from='yyy@184.73.164.51/spark' to='ken@184.73.164.51/424978324712783686768453' id='Oj02v-45'><status>Away due to idle.</status><priority>0</priority><show>away</show><x xmlns='vcard-temp:x:update'><photo>a3f549fa9705e7ead2905de0b6a804227ecdd404</photo></x><x xmlns='jabber:x:avatar'><hash>a3f549fa9705e7ead2905de0b6a804227ecdd404</hash></x></presence>
所以在这种情况下,我假设 a3f549fa9705e7ead2905de0b6a804227ecdd404 是照片数据。 那么如何将其传输到 NSData 中呢?
我想如果我能得到 NSData 对象, 我可以轻松创建 UIImage,对吗?
我认为“a3f549fa9705e7ead2905de0b6a804227ecdd404”是照片数据 这是我的代码:
NSString* command = @"a3f549fa9705e7ead2905de0b6a804227ecdd404";
command = [command stringByReplacingOccurrencesOfString:@" " withString:@""];
NSMutableData *commandToSend= [[NSMutableData alloc] init];
unsigned char whole_byte;
char byte_chars[3] = {'\0','\0','\0'};
int i;
for (i=0; i < [command length]/2; i++) {
byte_chars[0] = [command characterAtIndex:i*2];
byte_chars[1] = [command characterAtIndex:i*2+1];
whole_byte = strtol(byte_chars, NULL, 16);
[commandToSend appendBytes:&whole_byte length:1];
}
UIImage *image = [UIImage imageWithData: commandToSend];
然而, 它不起作用。 有谁知道这是怎么回事?
【问题讨论】:
标签: iphone sdk uiimage xmpp nsdata