checking if uiimage supports the scale parameter for retina display phones (only supported form ios 4 onwards)

This commit is contained in:
Sebastian Vieira 2012-01-17 16:34:44 +01:00 committed by Olivier Poitrey
parent baea8eed4a
commit 3ef0f609fd
2 changed files with 13 additions and 6 deletions

View File

@ -174,11 +174,14 @@ static SDImageCache *instance;
NSData *imageData = [NSData dataWithContentsOfFile:file]; NSData *imageData = [NSData dataWithContentsOfFile:file];
if (imageData) { if (imageData) {
UIImage *image = [[[UIImage alloc] initWithData:imageData ] autorelease]; UIImage *image = [[[UIImage alloc] initWithData:imageData ] autorelease];
CGFloat scale = 1.0; if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
if ([fileKey hasSuffix:@"@2x.png"] || [fileKey hasSuffix:@"@2x.jpg"]) { CGFloat scale = 1.0;
scale = 2.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; return nil;
} }

View File

@ -131,8 +131,12 @@ NSString *const SDWebImageDownloadStopNotification = @"SDWebImageDownloadStopNot
scale = 2.0; scale = 2.0;
} }
UIImage *image = [[[UIImage alloc] initWithData:imageData ] autorelease]; UIImage *image = [[UIImage alloc] initWithData:imageData ];
image = [[UIImage alloc] initWithCGImage:image.CGImage scale:scale orientation:UIImageOrientationUp]; 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 #ifdef ENABLE_SDWEBIMAGE_DECODER
[[SDWebImageDecoder sharedImageDecoder] decodeImage:image withDelegate:self userInfo:nil]; [[SDWebImageDecoder sharedImageDecoder] decodeImage:image withDelegate:self userInfo:nil];