【问题标题】:Screen capture with UIView and background in iOs在 iOs 中使用 UIView 和背景进行屏幕截图
【发布时间】:2012-06-26 11:01:59
【问题描述】:

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

- (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 内容。

【问题讨论】:

    标签: iphone screenshot cgimage eaglview


    【解决方案1】:

    我自己终于找到了答案。这是一个棘手的问题,我不确定是否有其他适当的方法可以做到这一点。对于我的需要,它运行良好。我所做的是,只需隐藏不应包含在屏幕截图图像中的子视图,并在捕获图像后取消隐藏子视图。

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

    【讨论】:

      【解决方案2】:

      指定要捕获的视图,而不是

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

      使用

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

      如果您的 EAGLView 是您的 imageView 的子视图,这是您要捕获的视图的子视图,这将起作用

      【讨论】:

      • EAGLView 是视图的子视图,ImageView 也是视图的子视图。但是它的层次排列就像EAGLView在顶部,inage view在中间,在底部View。
      • 如果我像你说的那样更改代码,它等于 self.view.layer 对吗?但在这种情况下,我从该视图中获取所有子视图。对不起,我错过了我的问题的一点,请检查更新的问题。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-04-29
      • 1970-01-01
      • 2016-02-14
      • 1970-01-01
      • 1970-01-01
      • 2014-07-30
      • 2017-01-07
      相关资源
      最近更新 更多