【问题标题】:How to get a screenshot of a CATiledLayer based TilingView如何获取基于 CATiledLayer 的 TilingView 的屏幕截图
【发布时间】:2015-05-23 13:01:31
【问题描述】:

我正在我的应用程序中尝试截取当前屏幕内容的屏幕截图,其中我的 TilingView(基于 CATiledLayers)显示了许多透明的大平铺图像。 我还在 TilingView 中添加了一些子视图,这些子视图在屏幕截图中神奇地捕捉到了,但是没有捕捉到 TilingView 的底层内容!??

以下代码-sn-ps 拍摄可见屏幕的快照,这似乎适用于基于 NON CATiledLayer 的视图层次结构,但不幸的是不适用于我的设置。即使我通过了 TilingView 的最顶层超级视图(作为实际的 UIViewController.view),我也只能在我的快照中看到 StatusBar、NavigationBar、TilingViews 子视图和 TabBar,但同样看不到 TilingViews 内容。

- (UIImage*)captureView:(UIView *)viewToCapture {
    CGRect rect = [[UIScreen mainScreen] bounds];
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    [viewToCapture.layer renderInContext:context];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}

有人知道或看到我缺少什么吗?我是否需要通过一些对我来说未知的 CG-API 调用来深入研究与 CG 相关的显示堆栈?提前致谢。

【问题讨论】:

    标签: ios screenshot catiledlayer uigraphicscontext


    【解决方案1】:

    通过在 StackOverflow 中搜索更多内容,我发现代码似乎可以满足我的要求。基本上我需要把上面的方法改成:

    - (UIImage*)captureView:(UIView*)viewToCapture {
        UIGraphicsBeginImageContextWithOptions(viewToCapture.bounds.size, NO, [UIScreen mainScreen].scale);
        [viewToCapture drawViewHierarchyInRect:viewToCapture.bounds afterScreenUpdates:YES];
        UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return image;
    }
    

    感谢提问/回答:How to get a screenshot of a view containing GPUImageView?

    【讨论】:

      猜你喜欢
      • 2021-09-06
      • 1970-01-01
      • 1970-01-01
      • 2014-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-13
      • 1970-01-01
      相关资源
      最近更新 更多