同问这个问题,目前想从缓存中获取 NSData,因为需要获取图片的 EXIF 信息
@onevcat 遇到一个问题,图片未被 Kingfisher 缓存时,可以获取到图片完整的 exif 信息,但是一旦被缓存后,我用
ImageCache.default.cachePath(forKey: urlString) 和 try? Data(contentsOf: URL(fileURLWithPath: cachePath)) 获取到的 exif 信息却严重丢失了
所以猜测当缓存的时候,原图被处理过才进行的缓存。 看到在进行缓存的时候,可以将 Data 传递给缓存图片的 original: Data 参数,只是在从缓存拿数据的时候,只看到了 Image,没有找到暴露出来的 original,不知如何解决,也在 Stack Overflow 搜索了许久,没有找到如何解决缓存后的数据 exif 丢失的问题,所以迫不得已只能在此求助了。
@Haojen
Kingfisher will use a default CacheSerializer to encode the processed image data when storing it to disk. If you need to keep all the original data (including exif), you could implement your own serializer to just store the original data.
See our wiki to know how to write and apply a custom serializer. Once you have an image from original data, you should be able to get the exif from it.
@onevcat 非常感谢你能抽出宝贵时间,对我的疑惑进行详细的解答,这个问题我在昨天晚些时候解决了,就是在研究阁下的文档时,用自订 CacheSerializer 的方式解决了问题。
再次感谢,能得到您的帮助,倍感荣幸。
日安
Most helpful comment
@Haojen
Kingfisher will use a default
CacheSerializerto encode the processed image data when storing it to disk. If you need to keep all the original data (including exif), you could implement your own serializer to just store the original data.See our wiki to know how to write and apply a custom serializer. Once you have an image from original data, you should be able to get the exif from it.