我只想打开闪光灯来拼接照片我正在尝试使用 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的主要内容,如果未能解决你的问题,请参考以下文章

即使打开闪光灯,AVCaptureOutput 也会拍摄暗照片

opengl - 闪光(如拍摄时)

如何不从照片库 iOS 中获取屏幕截图

在android中动态打开相机闪光灯

无法让安卓闪光灯小部件打开闪光灯

我正在尝试找出 macOS 中的数字格式化程序,我只想允许数字和小数点,但我遇到了麻烦