I am using AVFoundation to take a picture automatically, but the pictures are coming out very dark. The back camera is ok if you use the flash on an iPhone 4, but the front camera is basically a black sq开发者_运维技巧uare with only the faintest outline of the objects in the picture.
I have the following set for both cameras, but it does not seem to make a difference:
if (device.hasFlash) {
NSLog(@"device.hasFlash turning flash mode on");
[device lockForConfiguration:&deviceError];
device.flashMode = AVCaptureFlashModeOn;
[device unlockForConfiguration];
}
else {
NSLog(@"Device does not have Flash");
}
if ([device isFocusModeSupported:AVCaptureFocusModeContinuousAutoFocus]) {
NSLog(@"Enabling ContinuousAutoFocus");
[device lockForConfiguration:&deviceError];
device.focusMode = AVCaptureFocusModeContinuousAutoFocus;
[device unlockForConfiguration];
}
else {
NSLog(@"Device does not support ContinuousAutoFocus");
}
if ([device isExposureModeSupported:AVCaptureExposureModeContinuousAutoExposure]) {
NSLog(@"Enabling ContinuousAutoExposure");
[device lockForConfiguration:&deviceError];
device.exposureMode = AVCaptureExposureModeContinuousAutoExposure;
[device unlockForConfiguration];
}
else {
NSLog(@"Device does not support ContinuousAutoExposure");
}
if ([device isWhiteBalanceModeSupported:AVCaptureWhiteBalanceModeContinuousAutoWhiteBalance]) {
NSLog(@"Enabling ContinuousAutoWhiteBalance");
[device lockForConfiguration:&deviceError];
device.whiteBalanceMode = AVCaptureWhiteBalanceModeContinuousAutoWhiteBalance;
[device unlockForConfiguration];
}
else {
NSLog(@"Device does not support ContinuousAutoWhiteBalance");
}
Any Ideas?
The front-facing camera takes a while to adjust its white balance. You may need to KVO the isAdjustingWhiteBalance device property and only trigger the capture after the property has gone from NO to YES and back to NO for the first time.
I also had this issue, as I created AVCaptureStillImageOutput before every capture. But some time is required for auto setup.
So to fix it I create AVCaptureStillImageOutput once with AVCaptureSession creation
精彩评论