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

时间:2011-06-11 00:48:31

标签: ios ios4 avfoundation

我已经想出了AVFoundation和ImageIO的实现来处理我的应用程序中的照片。不过,我有一个问题。即使闪光灯熄灭,我拍摄的图像也总是很暗。这是我使用的代码:

        [[self currentCaptureOutput] captureStillImageAsynchronouslyFromConnection:[[self currentCaptureOutput].connections lastObject]
                                        completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {

                                            [[[blockSelf currentPreviewLayer] session] stopRunning];
                                            if (!error) {
                                                NSData *data            = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
                                                CGImageSourceRef source = CGImageSourceCreateWithData((CFDataRef) data, NULL);

                                                if (source) {

                                                    UIImage *image = [blockSelf imageWithSource:source];
                                                    [blockSelf updateWithCapturedImage:image];
                                                    CFRelease(source);

                                                }

                                            }

                                        }];

是否有任何可能导致图像不包含闪光灯的东西?

1 个答案:

答案 0 :(得分:14)

如果AVCaptureSession在此次通话之前立即设置,我发现有时会出现黑暗图像。也许自动曝光和放大器需要一段时间。白平衡设置可自行调整。

解决方案是设置AVCaptureSession,然后等到AVCaptureDevice的adjustingExposureadjustingWhiteBalance属性都NO(用KVO观察这些),然后再调用-[AVCaptureStillImageOutput captureStillImageAsynchronouslyFromConnection: completionHandler:]

相关问题