diff --git a/SDImageCache.m b/SDImageCache.m index c0d7d273..be9e7d80 100644 --- a/SDImageCache.m +++ b/SDImageCache.m @@ -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 { NSString *key = [arguments objectForKey:@"key"]; NSMutableDictionary *mutableArguments = [[arguments mutableCopy] autorelease]; - - UIImage *image = [[[UIImage alloc] initWithContentsOfFile:[self cachePathForKey:key]] autorelease]; + + UIImage *image = [self imageForFile:key]; if (image) { #ifdef ENABLE_SDWEBIMAGE_DECODER @@ -247,7 +259,7 @@ static SDImageCache *instance; if (!image && fromDisk) { - image = [[[UIImage alloc] initWithContentsOfFile:[self cachePathForKey:key]] autorelease]; + UIImage *image = [self imageForFile:key]; if (image) { [memCache setObject:image forKey:key]; diff --git a/SDWebImageDownloader.m b/SDWebImageDownloader.m index 52d599c9..737e2bd5 100644 --- a/SDWebImageDownloader.m +++ b/SDWebImageDownloader.m @@ -125,7 +125,14 @@ NSString *const SDWebImageDownloadStopNotification = @"SDWebImageDownloadStopNot 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 [[SDWebImageDecoder sharedImageDecoder] decodeImage:image withDelegate:self userInfo:nil];