【问题标题】:iPhone iOS how to render a screenshot with a different resolution or scale?iPhone iOS 如何以不同的分辨率或比例渲染屏幕截图?
【发布时间】:2012-03-15 04:18:14
【问题描述】:
我正在尝试保存 iPhone 屏幕的屏幕截图,但结果以 1 倍比例显示。
例如,一个 320x480 像素的屏幕截图是 320x480 像素,当在视网膜显示器上显示时,它看起来很模糊。但如果我用主屏幕和电源按钮截屏,生成的图像是 640x960,在视网膜显示器上看起来很完美。 如何在考虑屏幕比例因子的情况下截取屏幕截图?
谢谢!
【问题讨论】:
标签:
iphone
ios
uiview
screenshot
【解决方案1】:
Try This:
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
UIGraphicsBeginImageContextWithOptions(self.window.bounds.size, NO, [UIScreen mainScreen].scale);
else
UIGraphicsBeginImageContext(self.window.bounds.size);
[self.window.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData * data = UIImagePNGRepresentation(image);
[data writeToFile:@"foo.png" atomically:YES];