Generate hash from UIImage

前端 未结 4 1688
忘了有多久
忘了有多久 2020-11-28 07:59

I\'m trying to compare two UIImages from the file system to see if they are the same. Obviously, I can\'t use NSObject\'s hash method, since this returns a hash of the objec

4条回答
  •  心在旅途
    2020-11-28 08:57

    A less than optimal solution:

    [ UIImagePNGRepresentation( uiImage1 ) isEqualToData: 
          UIImagePNGRepresentation( uiImage2 ) ];
    

    This basically compares the PNG encoded data of the 2 images. Since image similarity is a complex subject, better and faster solutions can be devised based on what exactly the end goal is (i.e. are you looking to compare images, pixel by pixel, or just approximate similarity, which could use a downsampled version of the source image, etc).

提交回复
热议问题