我正在使用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];
}
有人说可以通过曝光来调节亮度,但我不知道如何使用。特别是,我想在收缩时调节相机亮度。