AVCaptureSession 亮度

4

我正在使用AVFoundation开发一个使用前置摄像头的镜子应用程序。我已经完成了将相机屏幕显示到UIView上。但是如何调整亮度呢?代码如下:

-(void)AVCaptureInit {   
    mCameraAVSession = [[AVCaptureSession alloc] init];
    [mCameraAVSession setSessionPreset:AVCaptureSessionPresetPhoto];

    mCaptureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];

    NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
    for (AVCaptureDevice *device in devices) {
        if ([device position] == AVCaptureDevicePositionFront) {
            mCaptureDevice = device;
            break;
        }
    }

    //if ([mCaptureDevice hasTorch] && [mCaptureDevice hasFlash])
    {
        [mCaptureDevice lockForConfiguration:nil];
        // [mCaptureDevice setTorchMode:AVCaptureTorchModeOn];
        //[mCaptureDevice setExposurePointOfInterest:0.5];

        [mCaptureDevice setExposureMode:AVCaptureExposureModeManual];

        [mCaptureDevice unlockForConfiguration];
    }



    // [inputDevice setTorchModeOnWithLevel:0.5 error:NULL];

    NSError *error;
    AVCaptureDeviceInput *deviceInput = [AVCaptureDeviceInput deviceInputWithDevice:mCaptureDevice error:&error];

    if ([mCameraAVSession canAddInput:deviceInput]) {
        [mCameraAVSession addInput:deviceInput];
    }

    AVCaptureVideoPreviewLayer *previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:mCameraAVSession];
    [previewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
    CALayer *rootLayer = [mCameraView layer];
    [rootLayer setMasksToBounds:YES];
    CGRect frame = mCaptureView.frame;
    [previewLayer setFrame:frame];
    [rootLayer insertSublayer:previewLayer atIndex:0];

    mCameraImageOutput = [[AVCaptureStillImageOutput alloc] init];
    NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys:AVVideoCodecJPEG, AVVideoCodecKey, nil];
    [mCameraImageOutput setOutputSettings:outputSettings];


    [mCameraAVSession addOutput:mCameraImageOutput];

    [mCameraAVSession startRunning];

    [self setVisible:mCaptureImage IsVisible:NO];
}

有人说可以通过曝光来调节亮度,但我不知道如何使用。特别是,我想在收缩时调节相机亮度。


你有阅读文档吗?你是指图像曝光还是相机曝光? - Teja Nandamuri
感谢您的回复。这意味着相机曝光。 - Tim Rogers
1
https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVCaptureDevice_Class/#//apple_ref/doc/uid/TP40009520-CH1-SW15 - Teja Nandamuri
能否像iPhone上的默认相机应用程序一样,通过相机曝光来调节亮度? - Tim Rogers
是的。尝试这个例子 https://github.com/IFTTT/FastttCamera - Teja Nandamuri
我已经尝试过了,但是我没能成功。 - Tim Rogers
1个回答

3

手动(自定义)相机曝光的说明可以在WWDC2014 Session 508Manual AVCam Sample Code中找到。

您可以通过运行AVCamManual,点击曝光 > 自定义并拖动曝光滑块来尝试它。

在代码中,它归结为将AVCaptureDeviceexposureMode设置为AVCaptureExposureModeCustom并调用

if ([mCaptureDevice lockForConfiguration:&error]) {
    [mCaptureDevice setExposureModeCustomWithDuration:exposureDuration ISO:AVCaptureISOCurrent completionHandler:nil];
    [mCaptureDevice unlockForConfiguration];
}

p.s. 我不确定你从哪里得到了 AVCaptureExposureModeManual。它似乎并不存在。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接