私はこの16進数をWebサービスから取得しています
http://www.moodpin.it/cms/listar_avatar?id=9
NSData に変換して UIImageView を設定しようとしていますが、機能しません
これが私のコードです:
NSData *dataImage = [appDelegate hexStringToData:avatar.avatar];
[imageView setImage:[UIImage imageWithData:dataImage]];
- (NSData *) hexStringToData:(NSString *) aString
{
NSString *command = aString;
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];
}
NSLog(@"%@", commandToSend);
return commandToSend;
}