【问题标题】:AVCaptureSession BrightnessAVCaptureSession 亮度
【发布时间】:2016-01-19 19:56:57
【问题描述】:

我正在使用带有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];
}

有人说可以用曝光来调节亮度,但我不知道怎么用。特别是,我想在捏合时调整相机亮度。

【问题讨论】:

标签: ios objective-c avfoundation avcapturesession


【解决方案1】:

WWDC2014 Session 508Manual AVCam Sample Code 中描述了手动(自定义)相机曝光。

运行 AVCamManual,点击 Exposure > Custom 并拖动 Exposure 滑块,亲自尝试一下。

在代码中,归结为将您的 AVCaptureDevice exposureMode 设置为 AVCaptureExposureModeCustom 并调用

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

附言我不确定你从哪里得到AVCaptureExposureModeManual。它似乎不存在。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-02-28
    • 1970-01-01
    • 2011-06-20
    • 1970-01-01
    • 2013-05-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多