SDWebImage process images before caching

后端 未结 4 634
一生所求
一生所求 2020-12-13 11:18

I fetch a lot of images from the web, and they are all kind of sizes - they can be big, small etc..

So I can resize them when I display them in the cell but this is

4条回答
  •  爱一瞬间的悲伤
    2020-12-13 12:01

    Expansion on MaeSTRo's answer in Swift 3:

    myImageView.sd_setImage(with: imageUrl){ (image, error, cacheType, url) in
        guard let image = image, cacheType == .none else { return }
    
        DispatchQueue.global(qos: .userInitiated).async {
            let modifiedImage = myImageProcessor(image)
            SDWebImageManager.shared().saveImage(toCache: modifiedImage, for: imageUrl)
            DispatchQueue.main.async {
                myImageView.image = modifiedImage
                myImageView.setNeedsDisplay()
            }
        }
    }
    

提交回复
热议问题