我正在使用 AVCapture 框架在从相机拍照时设置闪烁的闪光灯。在这种方法中,我得到了几秒钟的闪光灯闪烁效果,但随后它就崩溃了。
下面是我已经完成的代码。
-(IBAction) a
{
_picker = [[UIImagePickerController alloc] init];
_picker.sourceType = UIImagePickerControllerSourceTypeCamera;
_picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
_picker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
_picker.showsCameraControls = YES;
_picker.navigationBarHidden =YES;
_picker.toolbarHidden = YES;
_picker.wantsFullScreenLayout = YES;
[_picker takePicture];
// Insert the overlay
OverlayViewController *overlay = [[OverlayViewController alloc] initWithNibName:@"OverlayViewController" bundle:nil];
overlay.pickerReference = _picker;
_picker.cameraOverlayView = overlay.view;
_picker.delegate = (id)self;
[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(flashLight_On_Off) userInfo:nil repeats:YES];
[self presentModalViewController:_picker animated:NO];
}
- (void)flashLight_On_Off
{
NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
for (AVCaptureDevice *device in devices)
{
if ([device hasFlash] == YES)
{
[device lockForConfiguration:nil];
if (bulPicker == FALSE)
{
[device setTorchMode:AVCaptureTorchModeOn];
bulPicker = TRUE;
}
else
{
[device setTorchMode:AVCaptureTorchModeOff];
bulPicker = FALSE;
}
[device unlockForConfiguration];
}
}
}
有什么问题吗?还有其他方法可以得到解决方案吗?在按下使用按钮之前,我还必须在拍摄图像后停止闪烁。
请建议我适当的解决方案。