Hi, I am using XMPP and XMPP will give me a photo data like the following: a3f549fa9705e7ead2905de0b6a804227ecdd404
So I assume the above data is the photo data and I assume that it's Hex data. (maybe I am wrong)
So I use the following to create the UIImage, but it doesn't work anyone know how to do it?
What I am trying to do is to change command from Hex String into 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];