如何使用captureStillImageAsynchronouslyFromConnection捕获多个镜头

时间:2015-02-19 16:59:57

标签: ios8 avfoundation

我正在尝试在ios8应用中实现多个镜头。 我正在使用llsimplecamera(https://github.com/omergul123/LLSimpleCamera),它是AvFoundation的包装,可以像我一样工作。 当我按下快门按钮时,调用'captureStillImageAsynchronouslyFromConnection'(AVCaptureStillImageOutput的一个实例的方法)并且一切正常,我获得了一张照片。 如果我尝试将'captureStillImageAsynchronouslyFromConnection'设置为捕获多个镜头,在循环中,我没有得到任何照片。 我尝试使用信号量技术:

    if ([self.captureDevice lockForConfiguration:nil]) {
    if ([self.captureDevice isFocusModeSupported:AVCaptureFocusModeLocked])
        [self.captureDevice setFocusMode:AVCaptureFocusModeLocked];
    if ([self.captureDevice isExposureModeSupported:AVCaptureExposureModeLocked])
        [self.captureDevice setExposureMode:AVCaptureExposureModeLocked];
    if ([self.captureDevice isWhiteBalanceModeSupported:AVCaptureWhiteBalanceModeLocked])
        [self.captureDevice setWhiteBalanceMode:AVCaptureWhiteBalanceModeLocked];
}

AVCaptureConnection *videoConnection = [self captureConnection];
videoConnection.videoOrientation = [self orientationForConnection];

dispatch_semaphore_t sync = dispatch_semaphore_create(0);
while(1)
{
    [self.stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error)
     {

         if (imageSampleBuffer != NULL)
         {
             NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer];
             UIImage *image = [UIImage imageWithData:imageData];
             NSLog(@"image %@",image);
         }
         dispatch_semaphore_signal(sync);
     }];
    dispatch_semaphore_wait(sync, DISPATCH_TIME_FOREVER);
}

return nil;

但我没有照片。 我究竟做错了什么 ? 提前谢谢

0 个答案:

没有答案