0
我使用XMPP和XMPP會給我一個照片數據如下所示: a3f549fa9705e7ead2905de0b6a804227ecdd404如何從十六進制數據創建UIIMage?
所以我認爲上面的數據是照片數據,我認爲這是十六進制數據。 (也許我錯了)
所以我用下面來創建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];