Mat*_*ler 2 iphone png uiimage nsdata 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);
}
Run Code Online (Sandbox Code Playgroud)
我知道他们是PNG图像.打印时,这两个描述都不是NULL.但他们是不平等的.
为什么会这样?
您不能指望图像的PNG表示保持相同的位.有多种方法可以对同一图像进行编码,并且可能还有可以在编码之间进行更改的元数据.
相反,您可以逐个像素地比较图像.请参阅以下内容以获取UIImage的像素数据:如何从UIImage(Cocoa Touch)或CGImage(Core Graphics)获取像素数据?
| 归档时间: |
|
| 查看次数: |
1697 次 |
| 最近记录: |