iphone上的相机应用程序的AVFoundation AVCaptureDevice设置是什么?

时间:2014-06-22 03:18:45

标签: ios xcode cocoa-touch camera avcapturesession

我想知道iPhone上的相机应用程序的AVCaptureDevice设置是什么。特别是AVCaptureExposureMode,AVCaptureFocusMode和AVCaptureWhiteBalanceMode。我正在尝试制作一个自定义相机,出于某种原因,我不能让照片的照明在聚焦时正确改变。我为我的相机设置了ExposurePointOfInterest和FocusPointOfInterest,但出于某种原因,似乎相机正确聚焦但是照明没有聚焦在我轻拍的地方。当我点击一个黑暗区域时,它不会像在相机应用程序中那样变亮。是否有一些我忘记设置的环境?这是我对相机进行聚焦的代码。

CGPoint touchPoint = [gesture locationInView:collectView];
float focus_x = touchPoint.x / collectView.frame.size.width;
float focus_y = touchPoint.y / collectView.frame.size.height;
NSError *tError = nil;
NSLog(@"previous: %.2f, %.2f", backCamera.focusPointOfInterest.x, backCamera.focusPointOfInterest.y);
if (isFrontCamera) {
    focus_x = collectView.frame.size.width - focus_x; //the view is mirrored for the front camera
    if ([frontCamera lockForConfiguration:&tError]) {
        if ([frontCamera isExposurePointOfInterestSupported]) {
            [frontCamera setExposurePointOfInterest:CGPointMake(focus_x, focus_y)];
            if ([frontCamera isExposureModeSupported:AVCaptureExposureModeAutoExpose]) {
                [frontCamera setExposureMode:AVCaptureExposureModeAutoExpose];
            }
        }
        if ([frontCamera isFocusPointOfInterestSupported]) {
            [frontCamera setFocusPointOfInterest:CGPointMake(focus_x, focus_y)];
            if ([frontCamera isExposureModeSupported:AVCaptureExposureModeAutoExpose]) {
                [frontCamera setExposureMode:AVCaptureExposureModeAutoExpose];
            }
        }
        if ([frontCamera isWhiteBalanceModeSupported:AVCaptureWhiteBalanceModeAutoWhiteBalance]) {
            [frontCamera setWhiteBalanceMode:AVCaptureWhiteBalanceModeAutoWhiteBalance];
        }
        [frontCamera unlockForConfiguration];
    }
    else {
        NSLog(@"Couldn't change focus point:%@",tError);
    }
}
else {
    if ([backCamera lockForConfiguration:&tError]) {
        if ([backCamera isExposurePointOfInterestSupported]) {
            [backCamera setExposurePointOfInterest:CGPointMake(focus_x, focus_y)];
            if ([backCamera isExposureModeSupported:AVCaptureExposureModeAutoExpose]) {
                [backCamera setExposureMode:AVCaptureExposureModeAutoExpose];
            }
        }
        if ([backCamera isFocusPointOfInterestSupported]) {
            [backCamera setFocusPointOfInterest:CGPointMake(focus_x, focus_y)];
            if ([backCamera isFocusModeSupported:AVCaptureFocusModeAutoFocus]) {
                [backCamera setFocusMode:AVCaptureFocusModeAutoFocus];
            }
        }
        if ([backCamera isWhiteBalanceModeSupported:AVCaptureWhiteBalanceModeAutoWhiteBalance]) {
            [backCamera setWhiteBalanceMode:AVCaptureWhiteBalanceModeAutoWhiteBalance];
        }
        [backCamera unlockForConfiguration];
    }
    else {
        NSLog(@"Couldn't change focus point:%@",tError);
    }
}

1 个答案:

答案 0 :(得分:0)

This document有很多内容,可以部分回答你的问题。

希望这有点帮助,因为我们无法分辨每个房产'相机应用的价值。