UIImagePNGRepresentation()返回不同的字节
我有一些透明的图像,我从文件系统加载到
UIImageView
视图。为了我的目的,我需要将UIImageView
中的图像与文件系统上的文件进行比较。所以我做了类似以下的事情:
NSString *directoryPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *imageFile = [NSString stringWithFormat:@"%@/image.png", directoryPath];
if ([[NSData dataWithContentsOfFile:imageFile] isEqualToData:UIImagePNGRepresentation([imageView image])]) {
NSLog(@"Equal");
} else {
NSString *dataDescription = [[[NSData dataWithContentsOfFile:feltFile] description] substringToIndex:100];
NSString *imageDescription = [[UIImagePNGRepresentation([backgroundImageView image]) description] substringToIndex:100]
NSLog(@"Unequal: %@ %@", dataDescription, imageDescription);
}
我知道他们是PNG图像。打印时,这两个描述都不是NULL。但他们是不平等的。
为什么会这样?
没有找到相关结果
已邀请:
2 个回复
郡晒景沧
桔适丛
将图像以其通用类型不可知的形式转换为具有标准化设置的PNG。多个PNG文件可以编码相同的图像,当您在PNG中读取时,会丢失关联的元数据,然后在您写出新的PNG文件时重新创建(可能会有所不同)。 你想要完成的是什么?告诉我们,我们可以为您提供更好的解决方案。