iOS使用AVCaptureSession自定义相机
2016-01-23 15:50
330 查看
关于iOS调用摄像机来获取照片,通常我们都会调用UIImagePickerController来调用系统提供的相机来拍照,这个控件非常好 用。但是有时UIImagePickerController控件无法满足我们的需求,例如我们需要更加复杂的OverlayerView,这时候我们就 要自己构造一个摄像机控件了。
这需要使用AVFoundation.framework这个framework里面的组件了,所以我们先要导入这个头文件,另外还需要的组件官方文档是这么说的:
● An instance of AVCaptureDevice to represent the input device, such as a camera or microphone
● An instance of a concrete subclass of AVCaptureInput to configure the ports from the input device
● An instance of a concrete subclass of AVCaptureOutput to manage the output to a movie file or still image
● An instance of AVCaptureSession to coordinate the data flow from the input to the output
这里我只构造了一个具有拍照功能的照相机,至于录影和录音功能这里就不加说明了。
总结下来,我们需要以下的对象:
?
我的习惯是在init方法执行的时候创建这些对象,然后在viewWillAppear方法里加载预览图层。现在就让我们看一下代码就清楚了。
?
这是获取前后摄像头对象的方法
?
接下来在viewWillAppear方法里执行加载预览图层的方法
?
注意以下的方法,在viewDidAppear和viewDidDisappear方法中启动和关闭session
?
接着我们就来实现切换前后镜头的按钮,按钮的创建我就不多说了
?
这是切换镜头的按钮方法
?
这是拍照按钮的方法
这样自定义照相机的简单功能就完成了,如果你想要再添加其他复杂的功能,可以参考一下下面这篇文章,希望对你们有所帮助。
http://course.gdou.com/blog/Blog.pzs/archive/2011/12/14/10882. href="http://www.2cto.com/kf/qianduan/css/" target=_blank>html
这需要使用AVFoundation.framework这个framework里面的组件了,所以我们先要导入这个头文件,另外还需要的组件官方文档是这么说的:
● An instance of AVCaptureDevice to represent the input device, such as a camera or microphone
● An instance of a concrete subclass of AVCaptureInput to configure the ports from the input device
● An instance of a concrete subclass of AVCaptureOutput to manage the output to a movie file or still image
● An instance of AVCaptureSession to coordinate the data flow from the input to the output
这里我只构造了一个具有拍照功能的照相机,至于录影和录音功能这里就不加说明了。
总结下来,我们需要以下的对象:
?
?
?
?
?
?
?
这样自定义照相机的简单功能就完成了,如果你想要再添加其他复杂的功能,可以参考一下下面这篇文章,希望对你们有所帮助。
http://course.gdou.com/blog/Blog.pzs/archive/2011/12/14/10882. href="http://www.2cto.com/kf/qianduan/css/" target=_blank>html
相关文章推荐
- IOS内存管理
- iOS中llvm-Obfuscation的配置
- 转:ios的crash框架方法论
- iOS数据保存总结
- iOS 获取手机型号
- iOS 抖动动画
- iOS里Toll-Free Bridging的桥接机制
- IOS学习笔记1
- IOS Zbar SD二维码扫描的使用
- React-Native 开发 android & ios App,共享一份代码
- iOS个人整理14-界面间传值:属性传值---代理传值---block传值---单例传值
- React-Native 开发 android & ios App,共享一份代码
- IOS项目集成ShareSDK分享登录功能
- IOS开发:手势识别器
- iostat查看io使用率
- 【转】iOS设计模式之观察者模式
- 一个iOS应用内购买模块的开发
- iOS设备、Icon、LaunchImage、图片分辨率
- iOS 点击屏幕 回收键盘
- IOS异步获取数据并刷新界面dispatch_async的使用方法