我玩过 AutoFocus、AutoExposure、AutoWhiteBalance 和 LowLightBoost,但仍然可以让相机图像显示与使用原生 iPhone 5 相机查看/捕获的图像一样亮。
不知道我做错了什么。以下是按下屏幕时设置自动相机功能的主要功能。自动对焦有效。但不确定自动曝光、白平衡和 LowLightBoost 是否也能正常工作,因为查看的暗项目不会像原生相机那样变亮。
下面的大部分代码取自 iosDev 中心站点上发布的 AVCam 示例。
提前致谢!
- (IBAction)focusAndExposeTap:(UIGestureRecognizer *)gestureRecognizer
{
CGPoint devicePoint = [(AVCaptureVideoPreviewLayer *)[[self previewView] layer] captureDevicePointOfInterestForPoint:[gestureRecognizer locationInView:[gestureRecognizer view]]];
[self focusWithMode:AVCaptureFocusModeAutoFocus exposeWithMode:AVCaptureExposureModeAutoExpose whiteBalanceWithMode:AVCaptureWhiteBalanceModeContinuousAutoWhiteBalance atDevicePoint:devicePoint monitorSubjectAreaChange:YES];
}
- (void)focusWithMode:(AVCaptureFocusMode)focusMode exposeWithMode:(AVCaptureExposureMode)exposureMode whiteBalanceWithMode:(AVCaptureWhiteBalanceMode)whiteBalanceMode atDevicePoint:(CGPoint)point monitorSubjectAreaChange:(BOOL)monitorSubjectAreaChange{
dispatch_async([self sessionQueue], ^{
AVCaptureDevice *device = [[self videoDeviceInput] device];
NSError *error = nil;
if ([device lockForConfiguration:&error])
{
if ([device isFocusPointOfInterestSupported] && [device isFocusModeSupported:focusMode])
{
[device setFocusMode:focusMode];
[device setFocusPointOfInterest:point];
}
NSLog(@"Pre-Exposure Mode Support?: %hhd", [device isExposurePointOfInterestSupported]);
if ([device isExposurePointOfInterestSupported] && [device isExposureModeSupported:exposureMode])
{
[device setExposureMode:exposureMode];
[device setExposurePointOfInterest:point];
}
NSLog(@"Pre-White Balance mode Support? %hhd", [device isWhiteBalanceModeSupported:whiteBalanceMode]);
if ([device isWhiteBalanceModeSupported:whiteBalanceMode])
{
[device setWhiteBalanceMode:whiteBalanceMode];
}
NSLog(@"Pre Low light mode: %hhd", [device isLowLightBoostSupported]);
if ([device isLowLightBoostSupported]){
[device setAutomaticallyEnablesLowLightBoostWhenAvailable:YES];
}
[device setSubjectAreaChangeMonitoringEnabled:monitorSubjectAreaChange];
[device unlockForConfiguration];
}
else
{
NSLog(@"%@", error);
}
});
}
最佳答案
我的猜测是问题出在你的 AVCaptureExposureMode
上。 .正如您可以从我的线程 here 中引用的那样, iOS 7 目前不支持AVCaptureExposureModeAutoExpose
在任何设备上。因此,exposurePointOfInterest
不会设置在您想要的点上。
您的程序甚至不会输入您的以下代码片段(您可以检查自己):
if ([device isExposurePointOfInterestSupported] && [device isExposureModeSupported:exposureMode])
{
[device setExposureMode:exposureMode];
[device setExposurePointOfInterest:point];
}
如果您想拥有自动公开功能,您可以使用
AVCaptureExposureModeContinuousAutoExpose
将曝光设置在某个点。然后监听(key-value observe KVO)isAdjustingExposure
AVCaptureDevice
的属性(property)知道曝光何时完成调整。完成后,将ExposureMode 设置为AVCaptureExposureModeLocked
.如果这没有帮助,请告诉我,否则您可以接受并投票赞成这个答案:)
关于ios - 如何生成与使用原生相机拍摄的图像一样明亮的 AVFoundation 相机图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21597653/