出于某种原因,iOS屏幕截图模糊不清

时间:2014-03-07 15:28:28

标签: ios iphone objective-c uiimage screenshot

我正在尝试捕捉我的应用程序内部的屏幕,它曾经工作得很好,但现在我只得到一个模糊的图像。那样:

blurry screen capture

这是我的代码:

- (UIImage *)takeScreenShotWithFrame:(CGRect)frame
{
    if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
        UIGraphicsBeginImageContextWithOptions(frame.size, NO, [UIScreen mainScreen].scale);
    } else {
        UIGraphicsBeginImageContext(frame.size);
    }
    [self.view drawViewHierarchyInRect:frame afterScreenUpdates:NO];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}

我做错了什么?

提前致谢!

1 个答案:

答案 0 :(得分:2)

而不是:

[self.view drawViewHierarchyInRect:frame afterScreenUpdates:NO];

尝试:

CGContextRef context = UIGraphicsGetCurrentContext();
[self.view.layer renderInContext:context];