我正在构建一个应用程序,我需要截取视图的截图,其子视图是相机会话(AVFoundation会话)。我试过这段代码:
CGRect rect = [self.containerView bounds];
UIGraphicsBeginImageContextWithOptions(rect.size,YES,0.0f);
CGContextRef context = UIGraphicsGetCurrentContext();
[self.containerView.layer renderInContext:context];
UIImage *capturedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
这有效地让我获得了视图的UIImage,只是相机会话是黑色的:
我尝试过私有方法UIGetScreenImage()
并且运行正常,但由于Apple不允许这样做,我无法使用它。我也试过Apple's docs中的那个,但它是一样的。我已经使用图层跟踪了AVFoundation会话的问题。我怎样才能做到这一点?该应用程序有一个容器视图,其中包含两个停止相机会话的视图。
答案 0 :(得分:2)
如果使用iOS 7,它相当简单,你可以从UIViewController做这样的事情:
UIView *snapshotView = [self.view snapshotViewAfterScreenUpdates:YES];
您也可以使用寡妇的这个链接:iOS: what's the fastest, most performant way to make a screenshot programatically?
对于iOS 6及更早版本,我只能找到以下Apple Technical Q& A:[如何获取包含UIKit和Camera元素的应用程序的屏幕截图?]
答案 1 :(得分:0)
我目前正在寻找这个问题的解决方案!
我目前正在外出,所以我无法测试我找到的内容,但请看一下这些链接:
Screenshots-A Legal Way To Get Screenshots 似乎它在正确的轨道上 - 这是 Example Project(here是最初的帖子)
当我设法让它工作时,我肯定会更新这个答案!