How to avoid duplicate images in the image gallery of an iOS device?

I want to save images to a gallery. But if the images are already available on photo galleries, then how to distinguish whether existing ones exist or not? I did not find the property as a unique identifier, or do I need to compare data using NSdata?

thanks..

+6
source share
2 answers

You can maintain a hash dictionary for each image in the photo gallery, and then show only additional images that have no hashes in the dictionary

As a reminder, you can check the object in the dictionary by doing:

if ([myDictionary objectForKey:variableStoringImageHash] == nil) { //No such image present } else { //image is present } 

A bit about image hashing, this might help: iPhone: A quick hash function for storing web images (url) as files (hashed file names)

+1
source

I'm not sure what what eitan27 says will work as an alternative, I would say that your best hope is to compare NSData objects. But this, as you can see, will become very tedious, since the library will have n number of images and comparing each of them for repetition does not make sense, but if you want to compare the data, you look at this one , which will give you a fraction of how comparable data.

0
source

Source: https://habr.com/ru/post/909162/


All Articles