ios开发点滴--摄像头的使用
来源:互联网 发布:淘宝女西装外套 编辑:程序博客网 时间:2024/06/06 22:09
- (BOOL) hasMultipleCameras {
NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
if (devices != nil && [devices count] > 1) return YES;
return NO;
}
- (AVCaptureDevice *)cameraWithPosition : (AVCaptureDevicePosition) position
{
NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
for (AVCaptureDevice *device in devices )
if ( device.position == position )
return device;
return nil ;
}
- (void) swapFrontAndBackCameras {
//check for available cameras!
if (![self hasMultipleCameras]) return;
//assumes session is running
NSArray *inputs = self.captureSession.inputs; //should only be one value!
for ( AVCaptureDeviceInput *captureDeviceInput in inputs ) {
AVCaptureDevice *device = captureDeviceInput.device ;
if ( [device hasMediaType:AVMediaTypeVideo ] ) {
AVCaptureDevicePosition position = device.position ;
AVCaptureDevice *newCamera = nil ;
AVCaptureDeviceInput *newInput = nil ;
if (position == AVCaptureDevicePositionFront)
newCamera = [self cameraWithPosition:AVCaptureDevicePositionBack];
else
newCamera = [self cameraWithPosition:AVCaptureDevicePositionFront];
[self initializeCaptureDevice:newCamera];
newInput = [AVCaptureDeviceInput deviceInputWithDevice:newCamera error:nil];
// beginConfiguration ensures that pending changes are not applied immediately
[self.captureSession beginConfiguration ];
[self.captureSession removeInput:captureDeviceInput]; //remove current
[self.captureSession addInput:newInput]; //add new
// Changes take effect once the outermost commitConfiguration is invoked.
[self.captureSession commitConfiguration];
break ;
}
}
}
上面的代码是使用前置摄像头和后置摄像头!
- ios开发点滴--摄像头的使用
- ios开发点滴-常量使用
- iOS开发点滴-lldb的使用方法
- ios开发点滴-uitabbar
- iOS开发点滴-网络流量
- iOS开发点滴-ALAssetsLibrary
- ios开发点滴-icon的使用
- iOS开发点滴-CocoaPods安装和使用教程
- iOS点滴-openSSH使用
- ios开发点滴-文件目录的访问
- ios开发点滴-AFNetworking 使用
- ios开发点滴-播放系统声音
- ios开发点滴-判断iphone5屏幕
- ios开发点滴-tableview image 缓存
- ios开发点滴-截屏幕方法
- ios开发点滴-合并库文件
- iOS开发点滴-添加阴影效果
- iOS开发点滴-添加阴影效果
- FTP实用类
- 黑马程序员-集合框架之Collection
- pthon wxPython GUI
- UNIX网络编程——原始套接字的魔力【下】
- Project configuration is not up-to-date with pom.xml错误解决方法
- ios开发点滴--摄像头的使用
- iOS 发布应用程序到App Store
- 递归3: 汉诺塔的递归与迭代实现
- 关于VS2012中Team Explorer访问在CodePlex项目
- 【Java工程师之路】[2-1.1]Oracle 11g安装图文攻略
- WF 2007 (UVaLive 2397) - Collecting Luggage
- UNIX网络编程——原始套接字的魔力【续】
- hadoop:用还是不用?
- JavaScript学习之道:js跳转页面方法