2010-07-01 15 views
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]; 

回答

1

該字符串長度爲40個字符,並且確實看起來是以十六進制編碼的。這使得160位信息。而這160讓我想起了SHA-1,按照本文件:

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

所以,你必須在這裏的是圖像的校驗和,而不是圖像本身。您需要閱讀文檔以瞭解如何獲取整個圖像。