iPhone iOS如何使用不同的分辨率或比例渲染屏幕截图?

时间:2012-03-15 04:18:14

标签: iphone ios uiview screenshot

我正在尝试保存iPhone屏幕的截图,但结果是以1倍的比例显示。

例如,一个320x480像素的截图是320x480像素,当在视网膜显示器上显示时,它看起来很模糊。但是,如果我使用主屏幕和电源按钮截取屏幕截图,结果图像为640x960,在视网膜显示屏上看起来很完美。 如何在考虑屏幕缩放系数的情况下拍摄屏幕截图?

谢谢!

1 个答案:

答案 0 :(得分:2)

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];