Я установил ISO и время экспозиции на ios, но яркость фото всегда разная.
Я хочу создать приложение для камеры с самоконтролем на ios, после того, как я установил время экспозиции и iso, яркость фото всегда будет разной после автоматической экспозиции для разных сцен. На iphone, кроме iso и времени экспозиции, которые влияют на яркость фотографии, любые другие параметры, которые я могу контролировать, влияют на яркость фотографии.
if ( self.session )
{
// AVCaptureSessionPresetHigh
if ( [self.session canSetSessionPreset:AVCaptureSessionPreset3840x2160] ) {
//设置为4K
self.session.sessionPreset= AVCaptureSessionPreset3840x2160;
}
/* 获取相机设备 */
if ( !self.device ) {
self.device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
}
/* 创建输入对象 */
NSError *error;
if (!self.input) //容错,如果input已存在则input关联的device配置关系就未丢失
{
//强制关联。device与input输出配置,如果监测到当前input失去生命
self.input = [[AVCaptureDeviceInput alloc] initWithDevice:self.device error:&error];
}
/* 更新相机输出对象 */
if ( self.outPut )
{
/* 视频格式 */
switch (picture_format)
{
case PICTURE_FORMAT_RGB: //RGB格式
[self.outPut setVideoSettings:@{(id)kCVPixelBufferPixelFormatTypeKey : [NSNumber numberWithInt:kCVPixelFormatType_32BGRA]}];
break;
case PICTURE_FORMAT_YUV: //YUV格式
[self.outPut setVideoSettings:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:kCVPixelFormatType_420YpCbCr8BiPlanarFullRange] forKey:(id)kCVPixelBufferPixelFormatTypeKey]];
break;
default:
[self.outPut setVideoSettings:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:kCVPixelFormatType_420YpCbCr8BiPlanarFullRange] forKey:(id)kCVPixelBufferPixelFormatTypeKey]];
break;
} // end of switch (pictureFormat)
[self.outPut setAlwaysDiscardsLateVideoFrames:YES];
/* 添加输入 */
if ( [self.session canAddInput:self.input] ) {
[self.session addInput:self.input];
}
/* 添加输出 */
if ([self.session canAddOutput:self.outPut]) {
[self.session addOutput:self.outPut];
}
/* 链接对象 */
AVCaptureConnection *connection = [self.outPut connectionWithMediaType:AVMediaTypeVideo];
/* 视频方向 */
connection.videoOrientation = AVCaptureVideoOrientationPortrait;
self.sesstion_connection = connection;
if ( [self.session canAddConnection:connection] ) {
[self.session addConnection:connection];
}
//kvo setting--->>>
self.exp_status = NO;
[self.input.device addObserver:self forKeyPath:@"exposureTargetOffset" options:NSKeyValueObservingOptionOld |NSKeyValueObservingOptionNew context:nil];
#if 0
NSError *error = nil;
if ( [self.input.device lockForConfiguration:&error] ) {
if ([self.input.device isExposureModeSupported:AVCaptureExposureModeAutoExpose]) {
self.input.device.exposurePointOfInterest = CGPointMake(0, 0);
[self.input.device setExposureMode:AVCaptureExposureModeAutoExpose];
}
[self.input.device unlockForConfiguration];
}
else {
NSLog( @"Could not lock device for configuration: %@", error );
}
#endif
//set the exposure target bias
if ( [self.input.device lockForConfiguration:nil] ) {
[self.input.device setExposureTargetBias:0 completionHandler:nil];
[self.input.device unlockForConfiguration];
}
else {
NSLog( @"Could not lock device for configuration: %@", error );
}
if ( [self.input.device lockForConfiguration:nil] ) {
[self.input.device setAutomaticallyAdjustsVideoHDREnabled:NO];
if ([self.input.device.activeFormat isVideoHDRSupported] ) {
[self.input.device setVideoHDREnabled:NO];
}
} else {
NSLog( @"Could not lock device for configuration...");
}
#if 0
if ( [self.input.device lockForConfiguration:nil] ) {
if ( [self.input.device isWhiteBalanceModeSupported:AVCaptureWhiteBalanceModeLocked] ) {
AVCaptureWhiteBalanceGains gains = {CAM_WHITEBALACE_R_VALUE, CAM_WHITEBALACE_G_VALUE, CAM_WHITEBALACE_B_VALUE};
[self.input.device setWhiteBalanceModeLockedWithDeviceWhiteBalanceGains:gains completionHandler:^(CMTime syncTime) {}];
}
} else {
NSLog( @"Could not lock device for configuration...");
}
#else
if ( [self.input.device lockForConfiguration:nil] ) {
if ( [self.input.device isWhiteBalanceModeSupported:AVCaptureWhiteBalanceModeAutoWhiteBalance] ) {
[self.input.device setWhiteBalanceMode:AVCaptureWhiteBalanceModeAutoWhiteBalance];
}
} else {
NSLog( @"Could not lock device for configuration...");
}
#endif
} // end of if (self.outPut)
}