I'm developing an app using Kingfisher library to load image from ulr and display in CollectionViewCell
. I'm trying to resize the image to fit the Contentview
of CollectionViewCell
.
I have tried ResizeProcessor
and ScaleFactor
from the library but the result image seem blur
. My implementation is below (function is call in CellForRowAtIndexPath
)
let url = photo.flickrImageURL("m")
let size = contentView.frame.size
print("size is \(size.debugDescription)")
let resizeProcessor = ResizingImageProcessor(referenceSize: size, mode: .aspectFit)
self.flickrPhoto.kf.setImage(with: url, options: [.backgroundDecode,.processor(resizeProcessor), .scaleFactor(UIScreen.main.scale),.cacheOriginalImage])
Is there anything that I did wrong? The quality of images
seem very blur.
You should set referenceSize
to size of imageView
instead of contentView
. As size of your contentView
will be bigger than your imageView
Change your code with below code:
let size = self.flickrPhoto.frame.size
UPDATED
Just found that ResizingImageProcessor
works on pixel instead of points so you need to multiply scale into image size like below:
let resizingProcessor = ResizingImageProcessor(referenceSize: CGSize(width: self.flickrPhoto.frame.size.width * UIScreen.main.scale, height: self.flickrPhoto.frame.size.height * UIScreen.main.scale))