【问题标题】:How to create UIIMage from Hex Data?如何从十六进制数据创建 UIIMage?
【发布时间】:2010-07-01 23:54:38
【问题描述】:

我正在使用 XMPP,XMPP 会为我提供如下照片数据: a3f549fa9705e7ead2905de0b6a804227ecdd404

所以我假设上面的数据是照片数据,我假设它是十六进制数据。 (也许我错了)

所以我使用以下方法来创建 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];

【问题讨论】:

    标签: objective-c uiimage nsdata


    【解决方案1】:

    字符串有 40 个字符长,看起来肯定是十六进制编码的。这产生了 160 位信息。而这个 160 让我想起了 SHA-1,根据这个文档:

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

    所以你在这里得到的是图像的校验和,而不是图像本身。您需要阅读文档以了解如何获取整个图像。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-27
      • 1970-01-01
      • 2014-02-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-14
      相关资源
      最近更新 更多