Objective-C: Comparing an image against another image that has been previously saved

前端 未结 2 2011
清酒与你
清酒与你 2020-12-20 16:00

I have a question about comparing UIImages in Objective-C when one image has already been through a save and load process using the NSSearchPathForDirectoriesInDomains metho

2条回答
  •  清歌不尽
    2020-12-20 16:08

    You can compare the image name or the image URL if it was downloaded from Internet, it will also be faster than comparing the images.

    Also, the problem is that by using the == operator you are comparing the memory addresses of the images 0x95614c0 and 0xde748f0. That's why is not equal. You are comparing if they are the same object, not if the images are equal.

    To compare images use: As mentioned on Fls'Zen answer.

    if ([UIImagePNGRepresentation(blackImage) isEqualToData:UIImagePNGRepresentation(greenImage)])
    

提交回复
热议问题