Andrew
Andrew

Reputation: 16051

Taking a screenshot in-app then putting it in a UIImageView does so at normal resolution

After zooming the iOS simulator up to 100%, i've noticed that my icons which are made by the app through taking a 'screenshot' of a view using this code are in normal resolution, whereas everything else appears to be in retina resolution:

UIGraphicsBeginImageContext(rect.size);
[object.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenShot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

Any ideas how to make it be in retina resolution?

Upvotes: 2

Views: 950

Answers (1)

BoltClock
BoltClock

Reputation: 723448

UIGraphicsBeginImageContext() is not Retina display-aware.

On iOS 4, you'll need to use UIGraphicsBeginImageContextWithOptions() instead, passing 0 as the last argument to have iOS automatically scale it based on the device's screen resolution:

UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0);
[object.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenShot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

Upvotes: 9

Related Questions