简体   繁体   English

如何避免iOS设备图库中的图像重复?

[英]How to avoid image duplication in image gallery of iOS device?

I want to store the images to photo gallary. 我想将图像存储到照片中。 But if images are already available at photo gallary then how to distinguish for whether imgaes are already exists or not? 但是如果图像已经可以在照片中获得,那么如何区分imga是否已经存在? I didnt find property like unique identifier or should i compare by taking data in the form of NSdata? 我没有找到像唯一标识符的属性,或者我应该通过采用NSdata形式的数据进行比较?

thanks.. 谢谢..

You can maintain a dictionary of hashes for each the image in the photo gallery, and then show only additional images who do not hashes are not present in the dictionary 您可以为照片库中的每个图像维护一个哈希字典,然后只显示没有哈希的其他图像不在字典中

As a reminder, you can check for an object in a dictionary by doing: 提醒一下,您可以通过执行以下操作来检查字典中的对象:

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

For a bit about hashing an image, this might help: iPhone: fast hash function for storing web images (url) as files (hashed filenames) 有关散列图像的一些信息,这可能会有所帮助: iPhone:快速散列函数,用于将Web图像(url)存储为文件(散列文件名)

I am not sure if what eitan27 says will work so as an alternative I would say that your best hope is comparing NSData objects. 我不确定eitan27说的是否会起作用,所以我会说你最好的希望是比较NSData对象。 But this as you can see will become very tedious as there will be n number of images in library and comparing each one for repetition does't make sense , still if you want to compare data you look at this answer which will give you a fraction of how much the data is matching. 但是你可以看到这将变得非常繁琐,因为在库中会有n个图像并且比较每个图像以进行重复是没有意义的,如果你想要比较数据你看这个答案会给你一个分数数据匹配的数量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM