我有一个 AVCaptureVideoPreviewLayer(可以很好地全屏显示视频),我试图在另一个我添加为 subview 的小 View 中显示一个小预览。为此,我尝试使用 renderInContext,但我得到的只是“预览 View ”中的黑屏。
[[self.captureView.layer.sublayers objectAtIndex:0] renderInContext:context];
任何其他层似乎工作正常并显示在我的“预览 View ”中,为什么 AVCaptureVideoPreviewLayer 没有?
最佳答案
AVCaptureVideoPreviewLayer 被实现为一个 OpenGL 层,它不实现 renderInContext 以及 CoreAnimation 组合模型的其他一些方面,无论这意味着什么。
Quoth Apple在 renderInContext 的 CALayer 文档中:
Important The Mac OS X v10.5 implementation of this method does not support the entire Core Animation composition model. QCCompositionLayer, CAOpenGLLayer, and QTMovieLayer layers are not rendered. Additionally, layers that use 3D transforms are not rendered, nor are layers that specify backgroundFilters, filters, compositingFilter, or a mask values. Future versions of Mac OS X may add support for rendering these layers and properties.
从 iOS 5.1.1 开始,情况仍然如此。
我的处理方式是使用 AVCaptureVideoDataOutput 并将捕获的样本缓冲区发送到名为 imageFromSampleBuffer: 的便捷代码样本中,该样本由 Apple 在 technical QA1702 中发布。 .
关于objective-c - AVCaptureVideoPreviewLayer 不适用于 renderInContext,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10270604/