Add another logic. to check UIAnimatedImage when there are no image format to detect, this should use GIF to encode
This commit is contained in:
parent
12bdd57f31
commit
6f8d83b2f2
|
@ -162,6 +162,7 @@ typedef NS_OPTIONS(NSUInteger, SDImageCacheOptions) {
|
|||
* @param key The unique image cache key, usually it's image absolute URL
|
||||
* @param toDisk Store the image to disk cache if YES. If NO, the completion block is called synchronously
|
||||
* @param completionBlock A block executed after the operation is finished
|
||||
* @note If no image data is provided and encode to disk, we will try to detect the image format (using either `sd_imageFormat` or `SDAnimatedImage` protocol method) and animation status, to choose the best matched format, including GIF, JPEG or PNG.
|
||||
*/
|
||||
- (void)storeImage:(nullable UIImage *)image
|
||||
forKey:(nullable NSString *)key
|
||||
|
@ -178,6 +179,7 @@ typedef NS_OPTIONS(NSUInteger, SDImageCacheOptions) {
|
|||
* @param key The unique image cache key, usually it's image absolute URL
|
||||
* @param toDisk Store the image to disk cache if YES. If NO, the completion block is called synchronously
|
||||
* @param completionBlock A block executed after the operation is finished
|
||||
* @note If no image data is provided and encode to disk, we will try to detect the image format (using either `sd_imageFormat` or `SDAnimatedImage` protocol method) and animation status, to choose the best matched format, including GIF, JPEG or PNG.
|
||||
*/
|
||||
- (void)storeImage:(nullable UIImage *)image
|
||||
imageData:(nullable NSData *)imageData
|
||||
|
|
|
@ -195,11 +195,16 @@
|
|||
// Check image's associated image format, may return .undefined
|
||||
SDImageFormat format = image.sd_imageFormat;
|
||||
if (format == SDImageFormatUndefined) {
|
||||
// If we do not have any data to detect image format, check whether it contains alpha channel to use PNG or JPEG format
|
||||
if ([SDImageCoderHelper CGImageContainsAlpha:image.CGImage]) {
|
||||
format = SDImageFormatPNG;
|
||||
// If image is animated, use GIF (APNG may be better, but has bugs before macOS 10.14)
|
||||
if (image.sd_isAnimated) {
|
||||
format = SDImageFormatGIF;
|
||||
} else {
|
||||
format = SDImageFormatJPEG;
|
||||
// If we do not have any data to detect image format, check whether it contains alpha channel to use PNG or JPEG format
|
||||
if ([SDImageCoderHelper CGImageContainsAlpha:image.CGImage]) {
|
||||
format = SDImageFormatPNG;
|
||||
} else {
|
||||
format = SDImageFormatJPEG;
|
||||
}
|
||||
}
|
||||
}
|
||||
data = [[SDImageCodersManager sharedManager] encodedDataWithImage:image format:format options:nil];
|
||||
|
|
Loading…
Reference in New Issue