开发者

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

开发者 https://www.devze.com 2023-03-09 02:30 出处:网络
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

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.la开发者_开发问答yer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenShot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

Any ideas how to make it be in retina resolution?


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();
0

精彩评论

暂无评论...
验证码 换一张
取 消