【发布时间】:2010-07-01 23:54:38
【问题描述】:
我正在使用 XMPP,XMPP 会为我提供如下照片数据: a3f549fa9705e7ead2905de0b6a804227ecdd404
所以我假设上面的数据是照片数据,我假设它是十六进制数据。 (也许我错了)
所以我使用以下方法来创建 UIImage,但它不起作用 有人知道怎么做吗?
我要做的是将命令从十六进制字符串更改为 NSData。
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];
【问题讨论】:
标签: objective-c uiimage nsdata