如何制作AVFoundation相机图像与原生相机一样明亮?

时间:2014-02-06 08:32:50

标签: 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);
    }
});
}

1 个答案:

答案 0 :(得分:0)

我的猜测是问题在于AVCaptureExposureMode。正如您可以从我的帖子here中引用,iOS 7目前不支持任何设备上的AVCaptureExposureModeAutoExpose。因此,exposurePointOfInterest不会设置在您想要的位置。

您的程序甚至不会输入以下代码片段(您可以自行检查):

if ([device isExposurePointOfInterestSupported] && [device isExposureModeSupported:exposureMode])
        {
            [device setExposureMode:exposureMode];
            [device setExposurePointOfInterest:point];
        }

如果您想拥有自动曝光功能,您可以使用AVCaptureExposureModeContinuousAutoExpose在特定点设置曝光。然后听(键值观察KVO)isAdjustingExposure的{​​{1}}属性,以了解曝光何时完成调整。一旦这样做,将setExposureMode设置为AVCaptureDevice

如果这没有用,请告诉我,否则你可以接受并提出这个答案:)