Since Kingfisher
introduced LocalFileImageDataProvider
from 5.0
. I decided to switch to Kingfisher
to load images from my disk instead of loading them directly. As they said,
// Compared to loading it directly,
// you can get benefit of using Kingfisher's extension methods,
// as well as applying `ImageProcessor`s and storing the image to `ImageCache` of Kingfisher.
It works great. since my images from disk are quite large (more than 1MB each).
So The question is If I resize image size by using DownsamplingImageProcessor
in UICollectionView's Cell
, am I still able to access the original size images in the "Image's detail" page to show the full resolution image by still using like this,
//The way loading image from "Image detail page"
let url = URL(fileURLWithPath: path)
let provider = LocalFileImageDataProvider(fileURL: url)
imageView.kf.setImage(with: provider)
So in "UICollectionView page" I can use it like this,
let url = URL(fileURLWithPath: path)
let provider = LocalFileImageDataProvider(fileURL: url)
let processor = DownsamplingImageProcessor(size: size)
imageView.kf.setImage(with: provider, options: [.processor(processor)])
So are they cached different images cache in the Kingfisher cache mechanism? Because they seem using the same cacheKey
in LocalFileImageDataProvider
.
public init(fileURL: URL, cacheKey: String? = nil) {
self.fileURL = fileURL
self.cacheKey = cacheKey ?? fileURL.absoluteString
}
Do I need to customise the the cacheKey
for those two different pages?
You do not need to use a different cache key. The processor
has an identifier and it will be used to calculate the final cache key when storing in the cache. So everything should be fine to you (as your code snippet).
You can just print out the image size in the image setting method completion handler to confirm the image you are loading.
imageView.kf.setImage(with: url) { result in
switch result {
case .success(let value):
// The image was set to image view:
print(value.image.size)
//...