如何在自定义相机上使用UISlider调整亮度?

时间:2015-10-13 11:53:57

标签: ios objective-c iphone ios8 ios9

iOS 8 Camara可以在点击camara时调整亮度。

enter image description here

我也试过这段代码但没有用。

  AVCaptureDevice *device =[AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];

  AVCaptureWhiteBalanceGains deviceWhiteBalance;// = [device deviceWhiteBalanceGains];

 AVCaptureWhiteBalanceTemperatureAndTintValues tempAndTint = [device temperatureAndTintValuesForDeviceWhiteBalanceGains:[device deviceWhiteBalanceGains]];

tempAndTint.temperature = (slider.value*100)*10000/100;
if (slider.value < 0.50) {
    tempAndTint.tint = -(slider.value*100)*150/100;
}
else{
    tempAndTint.tint = (slider.value*100)*150/100;
}


deviceWhiteBalance = [device deviceWhiteBalanceGainsForTemperatureAndTintValues:tempAndTint];
[device chromaticityValuesForDeviceWhiteBalanceGains:deviceWhiteBalance];


dispatch_async(dispatch_get_main_queue(), ^{

    AVCaptureDevice *device =[AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    if (device) {
        [device setWhiteBalanceModeLockedWithDeviceWhiteBalanceGains:deviceWhiteBalance completionHandler:^(CMTime syncTime) {

        }];
    }
});

1 个答案:

答案 0 :(得分:3)

我找到了解决方案。并获得ios 8.0版以下支持的所有新变化

AVCamMenual - ios 8 Camera features

enter image description here