ios - 如何生成与使用原生相机拍摄的图像一样明亮的 AVFoundation 相机图像?

标签 ios iphone camera avfoundation brightness

我玩过 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/

相关文章:

camera - 三个JS。如何实现 ZoomALL 并确保给定的框填充 Canvas 区域?

java - Android 拍照在 Android 4.1.1 版本失败但在 4.0.0 版本成功

ios - 对用户隐藏 UIActivityViewController 中的字符串

ios - self.navigationController 使用 Storyboard到 Storyboard导航始终返回 nil

iPhone : mkv/mka parsing libraries

iphone - 使用应用程序时禁用通知声音和振动

Android:我可以从网站上拍张照片并自动上传吗?

iOS 8 多个弹出窗口 - "Warning: Attempt to present * on * which is already presenting (null)"

ios - ObservableObject 正在更新所有 View 并导致 SwiftUI 中的菜单关闭

iphone - UIActionSheet,取消按钮运行方法