我只想打开闪光灯来拼接照片我正在尝试使用 AVCaptureDevice 和 AVCaptureFlashModeOn
Posted
技术标签:
【中文标题】我只想打开闪光灯来拼接照片我正在尝试使用 AVCaptureDevice 和 AVCaptureFlashModeOn【英文标题】:I just want to turn the flash on for stitching photo's I'm trying to use AVCaptureDevice and AVCaptureFlashModeOn 【发布时间】:2010-07-08 15:33:53 【问题描述】:-(IBAction)turningFlashOn:(id)sender
AVCaptureSession *captureSession = [[AVCaptureSession alloc] init];
AVCaptureDevice *videoCaptureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
NSError *error = nil;
AVCaptureDeviceInput *videoInput = [AVCaptureDeviceInput deviceInputWithDevice:videoCaptureDevice error:&error];
if (videoInput)
[captureSession addInput:videoInput];
AVCaptureVideoDataOutput* videoOutput = [[AVCaptureVideoDataOutput alloc] init];
[videoOutput setSampleBufferDelegate:self queue:dispatch_get_current_queue()];
[captureSession addOutput:videoOutput];
[captureSession startRunning];
videoCaptureDevice.torchMode = AVCaptureFlashModeOn;
我被要求使用 lockForConfiguration 但它不起作用,或者我使用错了。谁能告诉我我做错了什么?
【问题讨论】:
【参考方案1】:if([videoCaptureDevice lockForConfiguration])
[videoCaptureDevice setTorchMode:AVCaptureTorchModeOn];
[videoCaptureDevice unlockForConfiguration];
【讨论】:
[videoCaptureDevice setTorchMode:AVCaptureTorchModeOff];或者只是释放你的 AVCaptureSession 对象。哪个更合适。 您应该在释放会话之前致电[session stopRunning];
。在这里查看我的帖子:***.com/questions/3190034/…【参考方案2】:
- (void)flashLightOn
NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
for (AVCaptureDevice *device in devices)
if ([device hasFlash] == YES)
[device lockForConfiguration:nil];
[device setTorchMode:AVCaptureTorchModeOn];
[device unlockForConfiguration];
-(void)flashLightOff
NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
for (AVCaptureDevice *device in devices)
if ([device hasFlash] == YES)
[device lockForConfiguration:nil];
[device setTorchMode:AVCaptureTorchModeOff];
[device unlockForConfiguration];
【讨论】:
以上是关于我只想打开闪光灯来拼接照片我正在尝试使用 AVCaptureDevice 和 AVCaptureFlashModeOn的主要内容,如果未能解决你的问题,请参考以下文章