YYWebImage,SDWebImage和PINRemoteImage比较
共同的特性
- 以类别 api 下载远程图片。
- 图片缓存
- 图片提前解码
- 其他
图片框架比较
图片后处理
根据下面的比较,可以看出图片后处理方面,PINRemoteImage > YYWebImage > SDWebImage
YYWebImage:
- 支持不带标记的后处理。
/** Set the view's `image` with a specified URL. @param imageURL The image url (remote or local file path). @param placeholder he image to be set initially, until the image request finishes. @param options The options to use when request the image. @param manager The manager to create image request operation. @param progress The block invoked (on main thread) during image request. @param transform The block invoked (on background thread) to do additional image process. @param completion The block invoked (on main thread) when image request completed. */ - (void)yy_setImageWithURL:(nullable NSURL *)imageURL placeholder:(nullable UIImage *)placeholder options:(YYWebImageOptions)options manager:(nullable YYWebImageManager *)manager progress:(nullable YYWebImageProgressBlock)progress transform:(nullable YYWebImageTransformBlock)transform completion:(nullable YYWebImageCompletionBlock)completion;
SDWebImage: 不支持图片后处理。
PINRemoteImage:
- 支持带标记的图片后处理。对于同一张图片,当需要不同的后处理方式时(a 界面需要正圆角,b 界面需要小幅度的圆角),尤为有用。
“`
/**
Set placeholder on view and retrieve the image from the given URL, process it using the passed in processor block and set result on view. Call completion after image has been fetched, processed and set on view.@param url NSURL to fetch from.
@param placeholderImage PINImage to set on the view while the image at URL is being retrieved.
@param processorKey NSString key to uniquely identify processor. Used in caching.
@param processor PINRemoteImageManagerImageProcessor processor block which should return the processed image.
@param completion Called when url has been retrieved and set on view.
*/- (void)pin_setImageFromURL:(nullable NSURL )url placeholderImage:(nullable PINImage )placeholderImage processorKey:(nullable NSString *)processorKey processor:(nullable PINRemoteImageManagerImageProcessor)processor completion:(nullable PINRemoteImageManagerImageCompletion)completion;
“`
图片格式支持
根据下面的比较,可以看出图片格式支持方面,YYWebImage = SDWebImage = PINRemoteImage
另外对于 WebP 的支持,需要下载 google 的 libwebp pod,这就需要先配置命令行代理了,才能安装此 pod,命令行代理的配置就不在此说明了。
而 YYImage 是提前先把编译 webp 的源码,并打包成了 framework,直接引入到了项目里了,避免了配置代理的繁琐工作。编译 webp 成 framework 可以参考此文。
YYWebImage:
SDWebImage:
- GIF: FLAnimatedImage
- WebP: libwebp
PINRemoteImage:
- GIF: FLAnimatedImage
- WebP: libwebp
图片解码控制:
根据下面的比较,可以看出图片解码控制方面,PINRemoteImage > YYWebImage > SDWebImage
YYWebImage:
下载完图片,会自动解码,可根据参数
YYWebImageOptionIgnoreImageDecoding
来控制不解码。代码位置: YYWebImageOperation(connectionDidFinishLoading:) BOOL shouldDecode = (self.options & YYWebImageOptionIgnoreImageDecoding) == 0; BOOL allowAnimation = (self.options & YYWebImageOptionIgnoreAnimatedImage) == 0; UIImage *image; BOOL hasAnimation = NO; if (allowAnimation) { image = [[YYImage alloc] initWithData:self.data scale:[UIScreen mainScreen].scale]; if (shouldDecode) image = [image yy_imageByDecoded]; if ([((YYImag