From 3ef0f609fd42281c2adc86592932a53d0cd39f84 Mon Sep 17 00:00:00 2001 From: Sebastian Vieira Date: Tue, 17 Jan 2012 16:34:44 +0100 Subject: [PATCH] checking if uiimage supports the scale parameter for retina display phones (only supported form ios 4 onwards) --- SDImageCache.m | 11 +++++++---- SDWebImageDownloader.m | 8 ++++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/SDImageCache.m b/SDImageCache.m index be9e7d80..3bf426d9 100644 --- a/SDImageCache.m +++ b/SDImageCache.m @@ -174,11 +174,14 @@ static SDImageCache *instance; 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; + if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) { + CGFloat scale = 1.0; + if ([fileKey hasSuffix:@"@2x.png"] || [fileKey hasSuffix:@"@2x.jpg"]) { + scale = 2.0; + } + image = [[[UIImage alloc] initWithCGImage:image.CGImage scale:scale orientation:UIImageOrientationUp] autorelease]; } - return [[[UIImage alloc] initWithCGImage:image.CGImage scale:scale orientation:UIImageOrientationUp] autorelease]; + return image; } return nil; } diff --git a/SDWebImageDownloader.m b/SDWebImageDownloader.m index 737e2bd5..bded6aec 100644 --- a/SDWebImageDownloader.m +++ b/SDWebImageDownloader.m @@ -131,8 +131,12 @@ NSString *const SDWebImageDownloadStopNotification = @"SDWebImageDownloadStopNot scale = 2.0; } - UIImage *image = [[[UIImage alloc] initWithData:imageData ] autorelease]; - image = [[UIImage alloc] initWithCGImage:image.CGImage scale:scale orientation:UIImageOrientationUp]; + UIImage *image = [[UIImage alloc] initWithData:imageData ]; + if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) { + UIImage *originalImage = image; + image = [[UIImage alloc] initWithCGImage:originalImage.CGImage scale:scale orientation:UIImageOrientationUp]; + [originalImage release]; + } #ifdef ENABLE_SDWEBIMAGE_DECODER [[SDWebImageDecoder sharedImageDecoder] decodeImage:image withDelegate:self userInfo:nil];