我正在开发一个镜像应用程序使用前置摄像头与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];
}任何人都说通过曝光来调整亮度是可能的,但我不知道如何使用。特别是,我想调整相机的亮度,当我捏。
发布于 2016-01-19 11:56:57
手动(自定义)相机曝光描述在WWDC2014会话508和手动AVCam示例代码中。
通过运行AVCamManual、点击曝光>自定义并拖动曝光滑块,为您自己尝试。
在代码中,它归结为将AVCaptureDevice exposureMode设置为AVCaptureExposureModeCustom并调用
if ([mCaptureDevice lockForConfiguration:&error]) {
[mCaptureDevice setExposureModeCustomWithDuration:exposureDuration ISO:AVCaptureISOCurrent completionHandler:nil];
[mCaptureDevice unlockForConfiguration];
}附注:我不知道你从哪里来的AVCaptureExposureModeManual。它似乎不存在。
https://stackoverflow.com/questions/34815028
复制相似问题