How to download 1x iPad 1 images as 2x 2x images on iPhone?

I am working on a universal application with hundreds of background images. To save disk space and prevent further duplication and spam, I want to reuse non-retina @ 1x iPad images as retina @ 2x iPhone images.

Example:

background125_iPad@2x.png
background125_iPad.png

iPhone 4 and 5 have different aspect ratios, so I scale the 1024x768 images to fit.

But the problem is that if I use this on iPhone 5:

UIImage *img = [UIImage imageNamed:@"background125_iPad.png"];

then iOS will try to become smarter than me and choose a huge memory monster @ " background125_iPad@2x.png ".

Is there a way to say: β€œiOS, look. I'm smarter than you. I want you to download this file. And I really mean this file. THIS AND AND treat it as if it were a @ 2x version with a large by a factor of 2. " so that it really loads the requested file "background125_iPad.png", but then the UIImageView acts as if it had 512 x 384 pixels (= 1024x768 px)?

I guess there is UIImage imageNamedno way to go then?

+4
source share
2 answers

I do not think you can disable this functionality.

But you can always do this:

UIImage *img = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"background125_iPad" ofType:@"png"]];
UIImage *scaledImage = [UIImage imageWithCGImage:[img CGImage] 
                          scale:[[UIScreen mainScreen] scale]
                             orientation:img.imageOrientation];

. UIImage :)

+2

, , , :

UIImage *img = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"background125_iPad" ofType:@"png"]];
img = [UIImage imageWithCGImage:[tmpImage CGImage]
                                           scale:[[UIScreen mainScreen] scale]
                                     orientation:UIImageOrientationUp];

Grzegorz -imageWithContentsOfFile: [[UIScreen mainScreen] scale].

+1

All Articles