【1】SDWebImage 5.0
流程简述:
1.调用sd_setImageWithURL...
方法
2.调用sd_cancelImageLoadOperationWithKey
取消正在进行的任务
4.manager
调用 loadImageWithURL...
,加载图片。(如果url是失败过的或者重试也失败的请求,直接调用callCompletionBlockForOperation...
退出)
5.将任务operation
(SDWebImageCombinedOperation
类型)加入runningOperations
容器(NSMutableSet
)
6.调用callCacheProcessForOperation...
从缓存加载图片
1⃣️从内存中通过key
取相应的image
2⃣️从磁盘取相应data
,调用SDImageCodersManager
的decodedImageWithData...
进行解析,根据data的第一个字节判定图片类型,调用相关的解析类进行解析,磁盘的所有操作封装到了block
中并放在@autoreleasepool
中
解析的过程:
将data
类型转化为CGImageSourceRef
,通过CGImageSourceGetCount
获取相应的图片个数
如果是1,直接将 data
转为image
如果大于1,通过遍历CGImageSourceRef
从中取出CGImageRef
,并转化为image
存到帧数组
最后别放了释放CFRelease(CGImageSourceRef类型对象)
7.调用callDownloadProcessForOperation...
进行图片下载
8.下载完成调用callStoreCacheProcessForOperation...
,
可存储原始图片(包裹在@autoreleasepool
中),也可存储转化的图片(包裹在@autoreleasepool
中)
存到内存中:
存到磁盘中:
dispatch_async(self.ioQueue, ^{
@autoreleasepool {
//存储逻辑
1.检查图片是否包含alpha channel 设置图片的类型 png或者jpeg
2.根据格式编码成data类型(通过CGImageDestinationRef 和 CGImageDestinationAddImage)
3.调用NSFileManager写入本地
}
});
网友评论