2016-01-15 34 views
3

我正在開發一款使用前置攝像頭的鏡像應用程序AVFoundation。我已經完成將相機屏幕顯示到UIView。但是我怎樣才能調節亮度? 的代碼是這樣的:AVCaptureSession亮度

-(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]; 
} 

有人說,這將有可能調整曝光亮度,但我不知道如何使用它。特別是,我想調整照相機的亮度,當我捏。

+0

您是否閱讀過文檔?你的意思是圖像曝光或照相機曝光? –

+0

感謝您的回覆。 這意味着相機曝光。 –

+1

https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVCaptureDevice_Class/#//apple_ref/doc/uid/TP40009520-CH1-SW15 –

回答

2

手冊(自定義)照相機曝光在WWDC2014 Session 508Manual AVCam Sample Code進行說明。

嘗試它爲你的自我運行AVCamManual,攻曝光>自定義並拖動滑塊曝光。

在代碼中,把它歸結爲你設置AVCaptureDeviceexposureModeAVCaptureExposureModeCustom並調用

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

附:我不確定你從哪裏得到AVCaptureExposureModeManual。它似乎並不存在。