Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AVCaptureOutput takes dark picture even with flash on

I have come up with an implementation of AVFoundation and ImageIO to take care of the photo taking in my application. I have an issue with it, however. The images I take are always dark, even if the flash goes off. Here's the code I use:

        [[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);

                                                }

                                            }

                                        }];

Is there anything there that could cause the image taken to not include the flash?

like image 610
Pier-Olivier Thibault Avatar asked Jun 11 '11 00:06

Pier-Olivier Thibault


1 Answers

I found I sometimes got dark images if the AVCaptureSession was set up immediately before this call. Perhaps it takes a while for the auto-exposure & white balance settings to adjust themselves.

The solution was to set up the AVCaptureSession, then wait until the AVCaptureDevice's adjustingExposure and adjustingWhiteBalance properties are both NO (observe these with KVO) before calling -[AVCaptureStillImageOutput captureStillImageAsynchronouslyFromConnection: completionHandler:].

like image 198
mrwalker Avatar answered Oct 14 '22 14:10

mrwalker