Add a better check to handle the cases when call `storeImage` without imageData. Firstly check SDAnimatedImage, then check sd_imageFormat.
This commit is contained in:
parent
f4548bba5c
commit
3df399508e
|
@ -187,14 +187,21 @@
|
|||
dispatch_async(self.ioQueue, ^{
|
||||
@autoreleasepool {
|
||||
NSData *data = imageData;
|
||||
if (!data && [image conformsToProtocol:@protocol(SDAnimatedImage)]) {
|
||||
// If image is custom animated image class, prefer its original animated data
|
||||
data = [((id<SDAnimatedImage>)image) animatedImageData];
|
||||
}
|
||||
if (!data && image) {
|
||||
// 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
|
||||
SDImageFormat format;
|
||||
if ([SDImageCoderHelper CGImageContainsAlpha:image.CGImage]) {
|
||||
format = SDImageFormatPNG;
|
||||
} else {
|
||||
format = SDImageFormatJPEG;
|
||||
}
|
||||
}
|
||||
data = [[SDImageCodersManager sharedManager] encodedDataWithImage:image format:format options:nil];
|
||||
}
|
||||
[self _storeImageDataToDisk:data forKey:key];
|
||||
|
|
Loading…
Reference in New Issue