其中其子视图是摄影机会话

其中其子视图是摄影机会话

本文介绍了拍摄UIView的屏幕快照,其中其子视图是摄影机会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个应用程序,在该应用程序中,我需要拍摄其子视图为摄影机会话(AVFoundation会话)的视图的屏幕快照.我已经尝试过以下代码:

I'm building an app where I need to take a screenshot of a view whose subviews are camera sessions (AVFoundation sessions). I've tried this code:

CGRect rect = [self.containerView bounds];
UIGraphicsBeginImageContextWithOptions(rect.size,YES,0.0f);
CGContextRef context = UIGraphicsGetCurrentContext();
[self.containerView.layer renderInContext:context];
UIImage *capturedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

有效地为我提供了带有视图的UIImage,只是相机会话为黑色:

Which effectively gets me an UIImage with the views, only that the camera sessions are black:

我已经尝试了私有方法UIGetScreenImage()并完美地工作,但是由于Apple不允许这样做,所以我无法使用它.我也在 Apple的文档中尝试了一个,但还是一样.我已使用图层将问题跟踪到AVFoundation会话.我怎样才能做到这一点?该应用程序具有一个容器视图,其中包含两个已停止的相机会话的视图.

I've tried the private method UIGetScreenImage() and works perfectly, but as Apple doesn't allows this, I can't use it. I've also tried the one in Apple's docs but it's the same. I've tracked the problem to AVFoundation sessions using layers. How can I achieve this? The app has a container view with two views which are stopped camera sessions.

推荐答案

如果使用iOS 7,这非常简单,您可以通过UIViewController进行如下操作:

If using iOS 7, it's fairly simple and you could do something like this from a UIViewController:

UIView *snapshotView = [self.view snapshotViewAfterScreenUpdates:YES];

您也可以从寡妇处使用此链接:

You can also use this link from a widow: iOS: what's the fastest, most performant way to make a screenshot programatically?

对于iOS 6及更低版本,我只能找到以下Apple技术问答:[如何截取同时包含UIKit和Camera元素的应用程序的屏幕截图?]

For iOS 6 and earlier, I could only find the following Apple Technical Q&A: [How do I take a screenshot of my app that contains both UIKit and Camera elements?]

  1. 捕获相机视图的内容.
  2. 将捕获的相机内容自己绘制到呈现UIKit元素的图形上下文中. (类似于您在代码中所做的事情)

这篇关于拍摄UIView的屏幕快照,其中其子视图是摄影机会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 23:02