ios – 如果尚未缓存,如何使用SDWebImageManager下载图像?

ios – 如果尚未缓存,如何使用SDWebImageManager下载图像?,第1张

概述我需要SDWeb ImageManager的完成处理程序功能(将下载缓存图像设置为黑白),所以我使用它而不是sd_setimage.我的问题是我无法弄清楚如何使用SDWebImageManager下载或获取图像的缓存版本.每次tableview单元格出列并重新加载时,图像都会重新下载.我尝试过设置选项:SDWebImageDownloaderOptions.useNSURLCache,但无济于 我需要SDWeb ImageManager的完成处理程序功能(将下载或缓存的图像设置为黑白),所以我使用它而不是sd_setimage.我的问题是我无法弄清楚如何使用SDWebImageManager下载或获取图像的缓存版本.每次tablevIEw单元格出列并重新加载时,图像都会重新下载.我尝试过设置选项:SDWebImageDownloaderOptions.useNSURLCache,但无济于事.任何建议将不胜感激!这是我的代码:

SDWebImageManager.shared().imageDownloader?.downloadImage(with:URL(string: imgurL),options: SDWebImageDownloaderOptions.useNSURLCache,progress: nil,completed: { (image,error,cacheType,url) in    if image != nil {      let beginImage = CIImage(image: image!)      let blackNwhiteimg = beginImage?.applyingFilter("CIcolorControls",withinputParameters: [kCIinputSaturationKey:0.0])      let newImage = UIImage(ciImage: blackNwhiteimg!)      cell.button.setimage(newImage,for: .normal)   }})
解决方法 从缓存中提取的更新答案:

SDWebImageManager.shared().loadImage(with: URL?,options: SDWebImageOptions,progress: { (Int,Int,URL?) in    code},completed: { (UIImage?,Data?,Error?,SDImageCacheType,Bool,URL?) in    code})

为了便于参考,我将在此屏幕截图中显示XCode在输入功能时显示的注释:

此外,SDWebImageManager文件中包含的注释:

/** * Downloads the image at the given URL if not present in cache or return the cached version otherwise. * * @param url            The URL to the image * @param options        A mask to specify options to use for this request * @param progressBlock  A block called while image is downloading *                       @note the progress block is executed on a background queue * @param completedBlock A block called when operation has been completed. * *   This parameter is required. *  *   This block has no return value and takes the requested UIImage as first parameter and the NSData representation as second parameter. *   In case of error the image parameter is nil and the third parameter may contain an NSError. * *   The forth parameter is an `SDImageCacheType` enum indicating if the image was retrIEved from the local cache *   or from the memory cache or from the network. * *   The fith parameter is set to NO when the SDWebImageProgressiveDownload option is used and the image is *   downloading. This block is thus called repeatedly with a partial image. When image is fully downloaded,the *   block is called a last time with the full image and the last parameter set to YES. * *   The last parameter is the original image URL * * @return Returns an NSObject conforming to SDWebImageOperation. Should be an instance of SDWebImageDownloaderOperation
总结

以上是内存溢出为你收集整理的ios – 如果尚未缓存,如何使用SDWebImageManager下载图像?全部内容,希望文章能够帮你解决ios – 如果尚未缓存,如何使用SDWebImageManager下载图像?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1209607.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-04
下一篇2022-06-04

发表评论

登录后才能评论

评论列表(0条)

    保存