public void AdjustExposure(int E) { if (E < 0 || E > 100) { return; } var error = new NSError(); float range = Math.Abs(maxExposure - minExposure); float factor = ((float)E / 100); var targetISO = factor * range + minExposure; if (device.LockingFocusWithCustomLensPositionSupported) { device.LockForConfiguration(out error); // changing just the shutter speed //var newDurationSeconds = factor * (maxDuration - minDuration) + minDuration; //device.LockExposure(CMTime.FromSeconds(newDurationSeconds, 1000 * 1000 * 1000), device.ISO, HandleAction); // changing just the shutter speed with a factor adjustment to the upper value //var newDurationSeconds = factor * (maxDuration * 0.02 - minDuration * 0.01) + minDuration; //device.LockExposure(CMTime.FromSeconds(newDurationSeconds, 1000 * 1000 * 1000),device.ISO,HandleAction); //changing the iso value //device.LockExposure(device.ExposureDuration, targetISO, HandleAction); // changin both iso and shutter speed //var newDurationSeconds = factor * ( maxDuration - minDuration) + minDuration; //device.LockExposure(CMTime.FromSeconds(newDurationSeconds, 1000 * 1000 * 1000), targetISO, HandleAction); // changin both iso and shutter speed { with factor 0.1 adjustment } if (factor < 0.75) { var newDurationSeconds = factor * (maxDuration * 0.0004 - minDuration * 0.0001) + minDuration; device.LockExposure(CMTime.FromSeconds(newDurationSeconds, 1000 * 1000 * 1000), targetISO, HandleAction); } else { var newDurationSeconds = Math.Pow(1.26, (100 * factor) - 74) * factor * (maxDuration * 0.0004 - minDuration * 0.0001) + minDuration; if (newDurationSeconds > maxDuration) { newDurationSeconds = maxDuration; } device.LockExposure(CMTime.FromSeconds(newDurationSeconds, 1000 * 1000 * 1000), targetISO, HandleAction); } device.UnlockForConfiguration(); } }
// //Camera Brigthness void SldBrightness_ValueChanged(object sender, EventArgs e) { if ( acdDevice.LockForConfiguration(out nsError) ) { // //Camera Values update acdDevice.LockExposure(acdDevice.ExposureDuration, sldBrightness.Value, null); // //Release Resourse acdDevice.UnlockForConfiguration(); } }
/* * Setting up camera setting for EOSpec: * Focus: 0.3 locked : Empirically chosen for set distance to current version of EOSpec * ISO : Avg between max and min ISO of device * Exposure : Empirically set to 1/10 * RGB gain: R and G normalized using max Gain values, * however Blue is normalized using min Gain value due to it saturating more than green and red channels (my phone: 1.858154 , 1 , 1) */ void ConfigureCameraForDevice(AVCaptureDevice device) { var error = new NSError(); if (device.IsFocusModeSupported(AVCaptureFocusMode.ContinuousAutoFocus)) { device.LockForConfiguration(out error); device.FocusMode = AVCaptureFocusMode.Locked; device.SetFocusModeLocked((float)0.3, null); Console.WriteLine("devidce device.FocusMode: " + device.FocusMode); device.UnlockForConfiguration(); } if (device.IsExposureModeSupported(AVCaptureExposureMode.ContinuousAutoExposure)) { device.LockForConfiguration(out error); device.ExposureMode = AVCaptureExposureMode.Custom; var iso = (device.ActiveFormat.MaxISO + device.ActiveFormat.MinISO) / 2; CMTime exposureTime = new CMTime(1, 10); device.LockExposure(exposureTime, iso, null); Console.WriteLine("deviceexposure: " + device.ExposureDuration + " = " + exposureTime + " iso: " + iso); device.UnlockForConfiguration(); //Setting RGB gains using WhiteBalance device.LockForConfiguration(out error); AVCaptureWhiteBalanceGains gains = device.DeviceWhiteBalanceGains; //normalizign Gains gains.RedGain = Math.Max(1, gains.RedGain); gains.GreenGain = Math.Max(1, gains.GreenGain); gains.BlueGain = Math.Min(1, gains.BlueGain); float maxGain = device.MaxWhiteBalanceGain; gains.RedGain = Math.Min(maxGain, gains.RedGain); gains.GreenGain = Math.Min(maxGain, gains.GreenGain); gains.BlueGain = Math.Min(maxGain, gains.BlueGain); Console.WriteLine("devidce device.WhiteBalanceMode gains RGB: " + gains.RedGain + " " + gains.GreenGain + " " + gains.BlueGain); device.SetWhiteBalanceModeLockedWithDeviceWhiteBalanceGains(gains, null); device.UnlockForConfiguration(); } }