首页 > 代码库 > IOS-闪光灯操作

IOS-闪光灯操作

AVCaptureDevice.h主要用来获取iphone一些关于相机设备的属性。前置和后置摄像头enum {AVCaptureDevicePositionBack                = 1,AVCaptureDevicePositionFront               = 2};typedef NSInteger AVCaptureDevicePosition;闪光灯开关 enum {AVCaptureFlashModeOff  = 0,AVCaptureFlashModeOn   = 1,AVCaptureFlashModeAuto = 2};typedef NSInteger AVCaptureFlashMode;手电筒开关 enum {AVCaptureTorchModeOff  = 0,AVCaptureTorchModeOn   = 1,AVCaptureTorchModeAuto = 2,};typedef NSInteger AVCaptureTorchMode;焦距调整 enum {AVCaptureFocusModeLocked              = 0,AVCaptureFocusModeAutoFocus           = 1,AVCaptureFocusModeContinuousAutoFocus = 2,};typedef NSInteger AVCaptureFocusMode;曝光量调节 enum {AVCaptureExposureModeLocked = 0,AVCaptureExposureModeAutoExpose = 1,AVCaptureExposureModeContinuousAutoExposure = 2,};typedef NSInteger AVCaptureExposureMode;白平衡 enum {AVCaptureWhiteBalanceModeLocked         = 0,AVCaptureWhiteBalanceModeAutoWhiteBalance         = 1,    AVCaptureWhiteBalanceModeContinuousAutoWhiteBalance = 2,};typedef NSInteger AVCaptureWhiteBalanceMode;

开启闪光灯:

 1 AVCaptureDevice* d = nil; // find a device by position  2 NSArray* allDevices = [AVCaptureDevice devices];  3 for (AVCaptureDevice* currentDevice in allDevices) {    4     if (currentDevice.position == AVCaptureDevicePositionBack) {  5             d = currentDevice;    6     }  7 } // at this point, d may still be nil, assuming we found something we like....  8 NSError* err = nil;  9 BOOL lockAcquired = [d lockForConfiguration:&err]; 10 if (!lockAcquired) {    11     // log err and handle... 12 } else {    13     // flip on the flash mode    14     if ([d hasFlash] && [d isFlashModeSupported:AVCaptureFlashModeOn] ) {       15     [d setFlashMode:AVCaptureFlashModeOn];    16     }    17     [d unlockForConfiguration]; 18 }

 

IOS-闪光灯操作