Fix disk image cache read not setting memory cache + ensure decodedImageWithImage never fail

This commit is contained in:
Olivier Poitrey 2012-11-06 10:14:21 +01:00
parent b5bb74bf96
commit 326890b476
2 changed files with 3 additions and 9 deletions

View File

@ -191,16 +191,10 @@ static const NSInteger kDefaultCacheMaxCacheAge = 60 * 60 * 24 * 7; // 1 week
dispatch_data_apply(dispatchedData, (dispatch_data_applier_t)^(dispatch_data_t region, size_t offset, const void *buffer, size_t size) dispatch_data_apply(dispatchedData, (dispatch_data_applier_t)^(dispatch_data_t region, size_t offset, const void *buffer, size_t size)
{ {
UIImage *diskImage = SDScaledImageForPath(key, [NSData dataWithBytes:buffer length:size]); UIImage *diskImage = [UIImage decodedImageWithImage:SDScaledImageForPath(key, [NSData dataWithBytes:buffer length:size])];
if (image) if (diskImage)
{ {
UIImage *decodedImage = [UIImage decodedImageWithImage:diskImage];
if (decodedImage)
{
diskImage = decodedImage;
}
[self.memCache setObject:diskImage forKey:key cost:image.size.height * image.size.width * image.scale]; [self.memCache setObject:diskImage forKey:key cost:image.size.height * image.size.width * image.scale];
} }

View File

@ -35,7 +35,7 @@
colorSpace, colorSpace,
bitmapInfo); bitmapInfo);
CGColorSpaceRelease(colorSpace); CGColorSpaceRelease(colorSpace);
if (!context) return nil; if (!context) return image;
CGRect rect = (CGRect){CGPointZero,{CGImageGetWidth(imageRef), CGImageGetHeight(imageRef)}}; CGRect rect = (CGRect){CGPointZero,{CGImageGetWidth(imageRef), CGImageGetHeight(imageRef)}};
CGContextDrawImage(context, rect, imageRef); CGContextDrawImage(context, rect, imageRef);