When store image with no data for SDImageCache, check whether it contains alpha to use PNG or JPEG format
This commit is contained in:
parent
bfe92374d0
commit
2872f94a3a
|
@ -217,8 +217,14 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
NSData *data = imageData;
|
NSData *data = imageData;
|
||||||
if (!data && image) {
|
if (!data && image) {
|
||||||
// If we do not have any data to detect image format, use PNG format
|
// If we do not have any data to detect image format, check whether it contains alpha channel to use PNG or JPEG format
|
||||||
data = [[SDWebImageCodersManager sharedInstance] encodedDataWithImage:image format:SDImageFormatPNG];
|
SDImageFormat format;
|
||||||
|
if (SDCGImageRefContainsAlpha(image.CGImage)) {
|
||||||
|
format = SDImageFormatPNG;
|
||||||
|
} else {
|
||||||
|
format = SDImageFormatJPEG;
|
||||||
|
}
|
||||||
|
data = [[SDWebImageCodersManager sharedInstance] encodedDataWithImage:image format:format];
|
||||||
}
|
}
|
||||||
[self storeImageDataToDisk:data forKey:key];
|
[self storeImageDataToDisk:data forKey:key];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue