在应用程序中截取屏幕截图然后将其放入UIImageView以正常分辨率进行

And*_*rew 2 iphone objective-c retina-display

在将iOS模拟器缩放到100%之后,我注意到应用程序通过使用此代码拍摄视图的"屏幕截图"而制作的图标处于正常分辨率,而其他所有图标都显示在视网膜分辨率中:

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

任何想法如何使其在视网膜分辨率?

Bol*_*ock 9

UIGraphicsBeginImageContext() 不是Retina显示器.

在iOS 4上,您需要使用UIGraphicsBeginImageContextWithOptions(),0作为最后一个参数传递,让iOS根据设备的屏幕分辨率自动缩放它:

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