Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retina image resources? #12

Open
grgcombs opened this issue Jul 17, 2011 · 2 comments
Open

Retina image resources? #12

grgcombs opened this issue Jul 17, 2011 · 2 comments

Comments

@grgcombs
Copy link

Any advice or information on how to use this to handle loading up retina (@2x) vs. standard resolution images?

@danilobuerger
Copy link

I solved this by replacing the following in EGOImageLoader:

- (void)imageLoadConnectionDidFinishLoading:(EGOImageLoadConnection *)connection {
    UIImage* anImage = [UIImage imageWithData:connection.responseData];
    ...

with:

- (void)imageLoadConnectionDidFinishLoading:(EGOImageLoadConnection *)connection {
    CFDataRef imageData = (CFDataRef)connection.responseData;
    CGDataProviderRef imageDataProvider = CGDataProviderCreateWithCFData(imageData);
    CGImageRef image = CGImageCreateWithPNGDataProvider(imageDataProvider, NULL, true, kCGRenderingIntentDefault);

    UIImage* anImage = [UIImage imageWithCGImage:image scale:[UIScreen mainScreen].scale orientation:UIImageOrientationUp];
    CGDataProviderRelease(imageDataProvider);
    CGImageRelease(image);
    ...

Works for PNGs. Replace CGImageCreateWithPNGDataProvider if you need something else.

@rnaud
Copy link

rnaud commented May 13, 2012

Two things in there : You can actually try for CGIImageCreatWithPNG and use JPEG if it failed like so :

- (void)imageLoadConnectionDidFinishLoading:(EGOImageLoadConnection *)connection {
  CFDataRef imageData = (CFDataRef)connection.responseData;
  CGDataProviderRef imageDataProvider = CGDataProviderCreateWithCFData(imageData);
  CGImageRef image = CGImageCreateWithPNGDataProvider(imageDataProvider, NULL, true, kCGRenderingIntentDefault);
  if (!image) image = CGImageCreateWithJPEGDataProvider(imageDataProvider, NULL, true, kCGRenderingIntentDefault);
  UIImage* anImage = [UIImage imageWithCGImage:image scale:[UIScreen mainScreen].scale orientation:UIImageOrientationUp];
  CGDataProviderRelease(imageDataProvider);
  CGImageRelease(image);

The other point is that you also need to do the same for the EGOCache class. I'm using that :

- (UIImage*)imageForKey:(NSString*)key {
  NSData* d = [[NSFileManager defaultManager] contentsAtPath:cachePathForKey(key)];
  if (d) {
    CFDataRef imageData = (CFDataRef) d;
    CGDataProviderRef imageDataProvider = CGDataProviderCreateWithCFData(imageData);
    CGImageRef image = CGImageCreateWithPNGDataProvider(imageDataProvider, NULL, true, kCGRenderingIntentDefault);
    if (!image) image = CGImageCreateWithJPEGDataProvider(imageDataProvider, NULL, true, kCGRenderingIntentDefault);
    UIImage* anImage = [UIImage imageWithCGImage:image scale:[UIScreen mainScreen].scale orientation:UIImageOrientationUp];
    CGDataProviderRelease(imageDataProvider);
    CGImageRelease(image);
    return anImage;
  } else {
    return nil;
  }  
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants