Laurent Crivello
Laurent Crivello

Reputation: 3931

Retina image displayed too big in retina simulator

I display a retina image (with @2x.png extension) using:

myImage = [UIImage imageNamed:@"[email protected]"];

UIGraphicsBeginImageContext(myImage.size);
[myImage drawAtPoint: CGPointZero];
myImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

imageView = [[UIImageView alloc] initWithImage:myImage];
NSLog(@"Dimension:%f x %f",myImage.size.width,myImage.size.height);
[self.view addSubview:imageView];

However the image is displayed twice its size on the retina simulation. Image and simulator both have 640 x 960 resolution, so I would expect the image filling the screen.
I know there are other ways than CGContext to display an image, but that's the way I would need to other purposes in my code.
Any idea why I have this definition issue ?

Upvotes: 1

Views: 399

Answers (2)

Sergei Belous
Sergei Belous

Reputation: 5038

Don't use @2x suffix

From apple documentation:

The UIImage class handles all of the work needed to load high-resolution images into your app. When creating new image objects, you use the same name to request both the standard and the high-resolution versions of your image. For example, if you have two image files, named Button.png and [email protected], you would use the following code to request your button image:

UIImage *anImage = [UIImage imageNamed:@"Button"];

Upvotes: 4

UpL1nK
UpL1nK

Reputation: 557

You do not need to explicitly load a retina image, @2x will be automatically appended to the image name if the device has a retina display.

Change your UIImage code to: myImage = [UIImage imageNamed:@"iPhoneBackground.jpg"];

Upvotes: 4

Related Questions