在AVCaptureSession运行时显示相机流 [英] Show camera stream while AVCaptureSession's running

查看:204
本文介绍了在AVCaptureSession运行时显示相机流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I was able to capture video frames from the camera using AVCaptureSession according to http://developer.apple.com/iphone/library/qa/qa2010/qa1702.html. However, it seems that AVCaptureScreen captures frames from the camera without showing the camera stream on the screen. I would like to also show camera stream just like in UIImagePicker so that the user knows that the camera is being turned on and sees what the camera is pointed at. Any help or pointer would be appreciated!

推荐答案

AVCaptureVideoPreviewLayer 正是您所需要的。

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

The code fragment Apple uses to demonstrate how to use it is:

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];

这篇关于在AVCaptureSession运行时显示相机流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆