gpt4 book ai didi

iphone - UIImagePNGRepresentation() 返回不同的字节

转载 作者:行者123 更新时间:2023-12-03 20:29:00 30 4
gpt4 key购买 nike

我有一些透明图像,正在从文件系统加载到 UIImageView View 中。出于我的目的,我需要将 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。但他们是不平等的。

为什么会发生这种情况?

最佳答案

您不能指望图像的 PNG 表示形式保持不变。有多种方法可以对同一图像进行编码,并且可能还存在可以在编码之间发生变化的元数据。

相反,您可以逐像素比较图像。请参阅以下内容以获取 UIImage 的像素数据:How to get pixel data from a UIImage (Cocoa Touch) or CGImage (Core Graphics)?

关于iphone - UIImagePNGRepresentation() 返回不同的字节,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4629773/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com