Adding the ability to render retina display images based on the file to which the url is pointing at

This commit is contained in:
Sebastian Vieira 2012-01-17 16:12:31 +01:00 committed by Olivier Poitrey
parent 6660c51d36
commit baea8eed4a
2 changed files with 24 additions and 5 deletions

View File

@ -169,13 +169,25 @@ static SDImageCache *instance;
} }
} }
} }
- (UIImage *) imageForFile:(NSString*)fileKey {
NSString *file = [self cachePathForKey:fileKey];
NSData *imageData = [NSData dataWithContentsOfFile:file];
if (imageData) {
UIImage *image = [[[UIImage alloc] initWithData:imageData ] autorelease];
CGFloat scale = 1.0;
if ([fileKey hasSuffix:@"@2x.png"] || [fileKey hasSuffix:@"@2x.jpg"]) {
scale = 2.0;
}
return [[[UIImage alloc] initWithCGImage:image.CGImage scale:scale orientation:UIImageOrientationUp] autorelease];
}
return nil;
}
- (void)queryDiskCacheOperation:(NSDictionary *)arguments - (void)queryDiskCacheOperation:(NSDictionary *)arguments
{ {
NSString *key = [arguments objectForKey:@"key"]; NSString *key = [arguments objectForKey:@"key"];
NSMutableDictionary *mutableArguments = [[arguments mutableCopy] autorelease]; NSMutableDictionary *mutableArguments = [[arguments mutableCopy] autorelease];
UIImage *image = [[[UIImage alloc] initWithContentsOfFile:[self cachePathForKey:key]] autorelease]; UIImage *image = [self imageForFile:key];
if (image) if (image)
{ {
#ifdef ENABLE_SDWEBIMAGE_DECODER #ifdef ENABLE_SDWEBIMAGE_DECODER
@ -247,7 +259,7 @@ static SDImageCache *instance;
if (!image && fromDisk) if (!image && fromDisk)
{ {
image = [[[UIImage alloc] initWithContentsOfFile:[self cachePathForKey:key]] autorelease]; UIImage *image = [self imageForFile:key];
if (image) if (image)
{ {
[memCache setObject:image forKey:key]; [memCache setObject:image forKey:key];

View File

@ -125,7 +125,14 @@ NSString *const SDWebImageDownloadStopNotification = @"SDWebImageDownloadStopNot
if ([delegate respondsToSelector:@selector(imageDownloader:didFinishWithImage:)]) if ([delegate respondsToSelector:@selector(imageDownloader:didFinishWithImage:)])
{ {
UIImage *image = [[UIImage alloc] initWithData:imageData]; CGFloat scale = 1.0;
NSString *lastPathComponent = url.lastPathComponent;
if ([lastPathComponent hasSuffix:@"@2x.png"] || [lastPathComponent hasSuffix:@"@2x.jpg"]) {
scale = 2.0;
}
UIImage *image = [[[UIImage alloc] initWithData:imageData ] autorelease];
image = [[UIImage alloc] initWithCGImage:image.CGImage scale:scale orientation:UIImageOrientationUp];
#ifdef ENABLE_SDWEBIMAGE_DECODER #ifdef ENABLE_SDWEBIMAGE_DECODER
[[SDWebImageDecoder sharedImageDecoder] decodeImage:image withDelegate:self userInfo:nil]; [[SDWebImageDecoder sharedImageDecoder] decodeImage:image withDelegate:self userInfo:nil];