我已经提出了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); } } }];
有什么可能导致图像不包括闪光灯吗?
解决方法
如果AVCaptureSession在此呼叫之前立即设置,我发现我有时会看到较暗的图像.也许需要一段时间的自动曝光和白平衡设置调整自己.
解决方案是设置AVCaptureSession,然后在调用之前等待AVCaptureDevice的adjustExposure和adjustWhiteBalance属性都为NO(在KVO中观察这些属性) – [AVCaptureStillImageOutput captureStillImageAsynchronouslyFromConnection:completionHandler:].