SDWebImage process images before caching

后端 未结 4 630
一生所求
一生所求 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:00

    SDWebImage 3.8.2

    If using UIImageView category sd_setImageWithURL. I have created another UIImageView category (extension)

    func modifiedImageFromUrl(url: NSURL?) {
        self.sd_setImageWithURL(url) { (image, error, cacheType, url) in
            if cacheType == SDImageCacheType.None && image != nil {
                dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0)) {
                    let modifiedImage = // modify image as you want
    
                    dispatch_async(dispatch_get_main_queue()) {
                        SDWebImageManager.sharedManager().saveImageToCache(modifiedImage, forURL: url)
    
                        self.image = modifiedImage
                    }
                }
            }
        }
    }
    

提交回复
热议问题