private void UpdateCameraPropertyRange(CameraPropertyCapabilities propertyCapabilities) { String text; if (IsSelectedCameraPropertySupported && propertyCapabilities.IsGetRangeSupported && propertyCapabilities.IsGetSupported) { CameraPropertyRange range = CurrentCamera.GetCameraPropertyRange(SelectedCameraProperty); text = String.Format("[ {0}, {1} ], step: {2}", range.Minimum, range.Maximum, range.Step); Int32 decimalPlaces; Decimal minimum, maximum, increment; if (IsCameraPropertyValueTypeValue) { minimum = range.Minimum; maximum = range.Maximum; increment = range.Step; decimalPlaces = 0; } else if (IsCameraPropertyValueTypePercentage) { minimum = 0; maximum = 100; increment = 0.01M; decimalPlaces = 2; } else { throw new NotSupportedException(String.Format("Camera property value type '{0}' is not supported.", ( String )cameraPropertyValueTypeSelection.SelectedItem)); } cameraPropertyValueValue.Minimum = minimum; cameraPropertyValueValue.Maximum = maximum; cameraPropertyValueValue.Increment = increment; cameraPropertyValueValue.DecimalPlaces = decimalPlaces; if (CurrentCameraPropertyRanges.ContainsKey(SelectedCameraProperty)) { CurrentCameraPropertyRanges[SelectedCameraProperty] = range; } else { CurrentCameraPropertyRanges.Add(SelectedCameraProperty, range); } CameraPropertyValue value = CurrentCamera.GetCameraProperty(SelectedCameraProperty, IsCameraPropertyValueTypeValue); SuppressCameraPropertyValueValueChangedEvent = true; cameraPropertyValueValue.Value = value.Value; cameraPropertyValueAuto.Checked = value.IsAuto; SuppressCameraPropertyValueValueChangedEvent = false; } else { text = "N/A"; } cameraPropertyRangeValue.Text = text; }
} // ctor public bool TryGetPropertyRange(VideoCaptureDevice device, out CameraPropertyRange range) { if (!device.GetCameraPropertyRange(property, out var minValue, out var maxValue, out var stepSize, out var defaultValue, out var flags)) { range = default(CameraPropertyRange); return(false); // failed to get range } if (minValue == maxValue) { range = default(CameraPropertyRange); return(false); // if MinValue==MaxValue the Property is not changeable by the user - thus will not be shown } range = new CameraPropertyRange(minValue, maxValue, stepSize, defaultValue, (flags & CameraControlFlags.Auto) == CameraControlFlags.Auto); return(true); } // func TryGetPropertyRange
private void cameraPropertyValueTypeSelection_SelectedIndexChanged(Object sender, EventArgs e) { if (CameraPropertyControlInitializationComplete) { CameraPropertyCapabilities propertyCapabilities = CurrentCameraPropertyCapabilities[SelectedCameraProperty]; CameraPropertyRange range = CurrentCameraPropertyRanges[SelectedCameraProperty]; Decimal previousValue = cameraPropertyValueValue.Value; UpdateCameraPropertyRange(propertyCapabilities); Decimal newValue; if (IsCameraPropertyValueTypeValue) // The previous value was a percentage. { newValue = range.DomainSize * previousValue / 100 + range.Minimum; } else if (IsCameraPropertyValueTypePercentage) // The previous value was a value. { newValue = (previousValue - range.Minimum) * 100 / range.DomainSize; } else { throw new NotSupportedException(String.Format("Camera property value type '{0}' is not supported.", ( String )cameraPropertyValueTypeSelection.SelectedItem)); } newValue = Math.Round(newValue); if (newValue > range.Maximum) { newValue = range.Maximum; } else if (newValue < range.Minimum) { newValue = range.Minimum; } SuppressCameraPropertyValueValueChangedEvent = true; cameraPropertyValueValue.Value = newValue; SuppressCameraPropertyValueValueChangedEvent = false; } }