-(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,但是它不起作用,或者我使用的是错误的。谁能告诉我我在做什么错?

最佳答案

if([videoCaptureDevice lockForConfiguration]) {
  [videoCaptureDevice setTorchMode:AVCaptureTorchModeOn];
  [videoCaptureDevice unlockForConfiguration];
 }

关于cocoa - 我只想打开闪光灯以缝制照片,我正在尝试使用AVCaptureDevice和AVCaptureFlashModeOn,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3205301/

10-10 06:22