首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AVCaptureSession亮度

AVCaptureSession亮度
EN

Stack Overflow用户
提问于 2016-01-15 15:58:12
回答 1查看 4.2K关注 0票数 4

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

代码语言:javascript
复制
-(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];
}

任何人都说通过曝光来调整亮度是可能的,但我不知道如何使用。特别是,我想调整相机的亮度,当我捏。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-01-19 11:56:57

手动(自定义)相机曝光描述在WWDC2014会话508手动AVCam示例代码中。

通过运行AVCamManual、点击曝光>自定义并拖动曝光滑块,为您自己尝试。

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

代码语言:javascript
复制
if ([mCaptureDevice lockForConfiguration:&error]) {
    [mCaptureDevice setExposureModeCustomWithDuration:exposureDuration ISO:AVCaptureISOCurrent completionHandler:nil];
    [mCaptureDevice unlockForConfiguration];
}

附注:我不知道你从哪里来的AVCaptureExposureModeManual。它似乎不存在。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34815028

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档