好吧,我哈希一个图像。正如你所知道的,哈希图像需要FOREVER。所以我拍摄了100个图像样本,均匀分布。这是代码。从const void转换为char?
#define NUM_HASH_SAMPLES 100
@implementation UIImage(Powow)
-(NSString *)md5Hash
{
NSData *data = UIImagePNGRepresentation(self);
char *bytes = (char*)malloc(NUM_HASH_SAMPLES*sizeof(char));
for(int i = 0; i < NUM_HASH_SAMPLES; i++)
{
int index = i*data.length/NUM_HASH_SAMPLES;
bytes[i] = (char)(data.bytes[index]); //Operand of type 'const void' where arithmetic or pointer type is required
}
unsigned char result[CC_MD5_DIGEST_LENGTH];
CC_MD5(bytes, NUM_HASH_SAMPLES, result);
return [NSString stringWithFormat:
@"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
result[0], result[1], result[2], result[3],
result[4], result[5], result[6], result[7],
result[8], result[9], result[10], result[11],
result[12], result[13], result[14], result[15]
];
}
错误发生在注释行上。
我在做什么错?
谢谢!但是,我发现做bytes [i] =&data.bytes [index]的时候有点干净。我的计算机科学教授告诉我,施放malloc是个好习惯。去搞清楚。 – rweichler
@rweichler他错了。此外,代码看起来不正确... – 2013-08-28 12:03:35