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,13 +187,20 @@
|
||||||
dispatch_async(self.ioQueue, ^{
|
dispatch_async(self.ioQueue, ^{
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
NSData *data = imageData;
|
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) {
|
if (!data && image) {
|
||||||
// If we do not have any data to detect image format, check whether it contains alpha channel to use PNG or JPEG format
|
// Check image's associated image format, may return .undefined
|
||||||
SDImageFormat format;
|
SDImageFormat format = image.sd_imageFormat;
|
||||||
if ([SDImageCoderHelper CGImageContainsAlpha:image.CGImage]) {
|
if (format == SDImageFormatUndefined) {
|
||||||
format = SDImageFormatPNG;
|
// If we do not have any data to detect image format, check whether it contains alpha channel to use PNG or JPEG format
|
||||||
} else {
|
if ([SDImageCoderHelper CGImageContainsAlpha:image.CGImage]) {
|
||||||
format = SDImageFormatJPEG;
|
format = SDImageFormatPNG;
|
||||||
|
} else {
|
||||||
|
format = SDImageFormatJPEG;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
data = [[SDImageCodersManager sharedManager] encodedDataWithImage:image format:format options:nil];
|
data = [[SDImageCodersManager sharedManager] encodedDataWithImage:image format:format options:nil];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue