在AVCaptureSession运行时显示摄像机流

时间:2010-08-02 01:58:17

标签: iphone avfoundation avcapturedevice avcapturesession

我能够根据http://developer.apple.com/iphone/library/qa/qa2010/qa1702.html使用AVCaptureSession从相机捕捉视频帧。但是,似乎AVCaptureScreen从相机捕获帧而不在屏幕上显示相机流。我想像UIImagePicker一样显示相机流,以便用户知道相机正在打开并看到相机指向的位置。任何帮助或指针将不胜感激!

1 个答案:

答案 0 :(得分:19)

AVCaptureVideoPreviewLayer正是您所寻找的。

Apple用于演示如何使用它的代码片段是:

AVCaptureSession *captureSession = <#Get a capture session#>;
AVCaptureVideoPreviewLayer *previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:captureSession];
UIView *aView = <#The view in which to present the layer#>;
previewLayer.frame = aView.bounds; // Assume you want the preview layer to fill the view.
[aView.layer addSublayer:previewLayer];