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];
}
有人說,這將有可能調整曝光亮度,但我不知道如何使用它。特別是,我想調整照相機的亮度,當我捏。
您是否閱讀過文檔?你的意思是圖像曝光或照相機曝光? –
感謝您的回覆。 這意味着相機曝光。 –
https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVCaptureDevice_Class/#//apple_ref/doc/uid/TP40009520-CH1-SW15 –