使用UIView和iOs中的背景进行屏幕截图

时间:2012-06-26 11:02:00

标签: iphone screenshot cgimage eaglview

在我的iPhone应用程序中,我正在拍摄设备的屏幕截图。在屏幕截图视图中,我有不同的层次结构视图,底部是空白背景视图,然后是背景图像视图,以及图像视图上的EAGLView。我想捕获具有EAGLView框架大小的设备的屏幕截图,它应该包括imageview和背景视图。这是我的代码:

- (IBAction)captureScreen:(id)sender{

    UIGraphicsBeginImageContext(self.view.bounds.size);

    [self.cameraAppView.layer renderInContext:UIGraphicsGetCurrentContext()]; // cameraAppView is the EAGLView

    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    CGImageRef imageRef = CGImageCreateWithImageInRect([viewImage CGImage], cameraAppView.frame);

    UIImage *img = [UIImage imageWithCGImage:imageRef];

    CGImageRelease(imageRef);
}

但是现在我只获得了EAGLView的屏幕截图,我希望通过EAGLView框架大小获得设备的屏幕截图。我怎么能这样做?

修改

对不起,我在提问中错过了一点。同一屏幕中还有一些其他子视图。但它们都是EAGLView的顶级产品。我想在EAGLView下面捕获视图的图像,包括EAGLView内容。

2 个答案:

答案 0 :(得分:1)

终于找到了答案。这是一个棘手的问题,我不确定是否还有其他正确的方法可以做到这一点。为了我的需要它完美地工作。我所做的就是隐藏不应包含在屏幕截图中的子视图,并在捕获图像后取消隐藏子视图。

如果有人发现任何人找到合适的方法,请分享。

答案 1 :(得分:0)

指定要捕获的视图而不是

[self.cameraAppView.layer renderInContext:UIGraphicsGetCurrentContext()];

使用

[self.cameraAppView.superView.superView.layer renderInContext:UIGraphicsGetCurrentContext()];

如果你的EAGLView是你想要捕获的视图的子视图的imageView的子视图,这将有效

相关问题