我正在使用AVFoundation构建自定义相机。除了setExposurePointOfInterest
之外,一切都很好。
我在iPhone 5上测试,AVCaptureDevice告诉我BackCamera不支持AVCaptureExposureModeAutoExpose
。
如何实施点按以调整曝光?
这是我的代码:
- (void)didTapCameraPreview:(UITapGestureRecognizer *)recognizer {
CGPoint point = [recognizer locationInView:self.view];
CGRect screenRect = [self.view bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
double focus_x = point.x/screenWidth;
double focus_y = point.y/screenHeight;
CGPoint touchPoint = CGPointMake(focus_x, focus_y);
AVCaptureDevice *device = (self.captureSession.inputs[0] == self.backCamera) ? self.backCamera.device : self.frontCamera.device;
if (device.isFocusPointOfInterestSupported) {
NSError *error;
if ([device lockForConfiguration:&error]) {
[device setFocusPointOfInterest:touchPoint];
[device setExposurePointOfInterest:touchPoint];
[device setFocusMode:AVCaptureFocusModeAutoFocus];
if ([device isExposureModeSupported:AVCaptureExposureModeAutoExpose]){
[device setExposureMode:AVCaptureExposureModeAutoExpose];
}
[device unlockForConfiguration];
}
}
}
答案 0 :(得分:4)
我在Apple开发者论坛上质疑类似的问题,并得到了Brad Ford(核心媒体工程)的回答,他是苹果公司WWDC中AV Foundation的Camera Capture发言人。
这是他的answer:
<强>正确。 AVCaptureExposureModeAutoExpose,虽然在标题中定义, 目前尚未在任何iOS设备上实施。
但是,您可以通过设置所需的代码在自己的代码中实现它 兴趣点,然后打电话 setExposureMode:AVCaptureExposureModeContinuousAutoExposure,然后 listen(键值观察)的“isAdjustingExposure”属性 AVCaptureDevice知道曝光何时完成调整。尽快 就像这样,将setExposureMode设置为AVCaptureExposureModeLocked。
希望它澄清并帮助!