我正在尝试捕捉我的应用程序内部的屏幕,它曾经工作得很好,但现在我只得到一个模糊的图像。那样:
这是我的代码:
- (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;
}
我做错了什么?
提前致谢!
答案 0 :(得分:2)
而不是:
[self.view drawViewHierarchyInRect:frame afterScreenUpdates:NO];
尝试:
CGContextRef context = UIGraphicsGetCurrentContext();
[self.view.layer renderInContext:context];