views:

28

answers:

2

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];
A: 

The Photo data "a3f549fa9705e7ead2905de0b6a804227ecdd404" looks like Hex data to me. Maybe I am wrong. Any idea?

A: 

The string is 40 characters long and surely looks hex-encoded. This makes 160 bits of information. And this 160 reminds me of SHA-1, in accordance with this document:

http://xmpp.org/extensions/xep-0153.html

So what you have here is the checksum of an image, not the image itself. You need to read the document to find out how to get the whole image.

Roland Illig