ios - AVCaptureSession 亮度

标签 ios objective-c avfoundation avcapturesession

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

有人说可以通过曝光调整亮度,但我不知道如何使用它。特别是,我想在捏合时调整相机亮度。

最佳答案

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

运行 AVCamManual,点击“曝光”>“自定义”并拖动“曝光” slider ,亲自尝试一下。

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

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

附注我不确定您从哪里获取 AVCaptureExposureModeManual。它似乎不存在。

关于ios - AVCaptureSession 亮度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34815028/

相关文章:

java - objective-C : extending UIViewController leads to unexpected sense of "self" and "super"

iphone - UIView 阴影不显示

ios - 保存旋转的图片(swift3)

ios - 使用 AVAssetWriter 而不是 AVAssetExportSession 导出 AVMutableVideoComposition

ios - 点击 UITextField 后跟 UIDatePicker 时,UITableView 向上滚动两次

ios - 使用 AVPlayer 从远程 URL 播放视频

iphone - 如何在iOS应用程序中根据文件夹结构中的格式对文件进行分组?

ios - 滚动 collectionView 单元格时更改 collectionView 外部的图像

ios - 如何检测 iOS 中 UITextView (UIScrollView) 故障的底部

objective-c - 使用 NSURLConnection 处理自签名证书