async private Task <PhotoCaptureDevice> InitCamera(CameraPreviewSettings settings, CameraSensorLocation loc) { PhotoCaptureDevice camera = await OpenCamera(settings.Width, settings.Height, loc); UInt32 iso = Helper.GetISO((UInt32)settings.ISO, loc); Nullable <UInt32> wb = Helper.GetWhiteBalance(settings.WhiteBalance, loc); CameraCapturePropertyRange focusRange = PhotoCaptureDevice.GetSupportedPropertyRange(loc, KnownCameraGeneralProperties.ManualFocusPosition); UInt32 focusDistance = settings.FocusDistance.Equals("min", StringComparison.OrdinalIgnoreCase) ? (UInt32)focusRange.Min : (UInt32)focusRange.Max; camera.SetProperty(KnownCameraPhotoProperties.ExposureCompensation, 0); camera.SetProperty(KnownCameraPhotoProperties.FlashMode, FlashState.Off); camera.SetProperty(KnownCameraPhotoProperties.FocusIlluminationMode, 0); if (wb.HasValue) { camera.SetProperty(KnownCameraPhotoProperties.WhiteBalancePreset, wb.Value); _waitForWb = true; Debug.WriteLine("Using WB value: {0}", wb.Value); } camera.SetProperty(KnownCameraPhotoProperties.Iso, iso); camera.SetProperty(KnownCameraGeneralProperties.ManualFocusPosition, focusDistance); Debug.WriteLine("Using ISO: {0}, Using Focus Distance: {1}", camera.GetProperty(KnownCameraPhotoProperties.Iso), camera.GetProperty(KnownCameraGeneralProperties.ManualFocusPosition)); return(camera); }
public override sealed void ReadCurrent() { try { CameraCapturePropertyRange range = PhotoCaptureDevice.GetSupportedPropertyRange(Device.SensorLocation, ParameterId); if (range == null) { IsSupported = false; } else { Minimum = (T)range.Min; Maximum = (T)range.Max; _value = (T)Device.GetProperty(ParameterId); IsSupported = true; } } catch (Exception) { IsSupported = false; } IsModifiable = IsSupported && !Minimum.Equals(Maximum); }
/// <summary> /// Reads supported ISO values from Parameter.Device and populates /// ArrayParameter.Options accordingly. Sets the SelectedOption as well. /// /// ISO auto value is set by setting the value in PhotoCaptureDevice API to /// null, therefore the separate handling for option "Auto". /// </summary> protected override void PopulateOptions() { ArrayParameterOption option = new ArrayParameterOption(null, "Auto", "Assets/Icons/overlay.iso.auto.png"); ArrayParameterOption selectedOption = option; Options.Add(option); CameraCapturePropertyRange range = PhotoCaptureDevice.GetSupportedPropertyRange(Device.SensorLocation, PropertyId); object value = Device.GetProperty(PropertyId); UInt32[] standardValues = { 100, 200, 400, 800, 1600, 3200 }; UInt32 min = (UInt32)range.Min; UInt32 max = (UInt32)range.Max; foreach (UInt32 i in standardValues) { if (i >= min && i <= max) { option = new ArrayParameterOption(i, "ISO " + i.ToString(), "Assets/Icons/overlay.iso." + i.ToString() + ".png"); Options.Add(option); if (i.Equals(value)) { selectedOption = option; } } } SelectedOption = selectedOption; }
/// <summary> /// Reads the range minimum, maximum and current value. Sets Supported and Modifiable /// appropriately. /// </summary> public override void Refresh() { try { CameraCapturePropertyRange range = PhotoCaptureDevice.GetSupportedPropertyRange(Device.SensorLocation, _propertyId); if (range == null) { Supported = false; } else { Minimum = (T)range.Min; Maximum = (T)range.Max; _value = (T)Device.GetProperty(_propertyId); Supported = true; } } catch (Exception) { Supported = false; System.Diagnostics.Debug.WriteLine("Getting " + Name.ToLower() + " failed"); } Modifiable = Supported && !_minimum.Equals(_maximum); if (Supported) { NotifyPropertyChanged("Value"); NotifyPropertyChanged("OverlaySource"); } }
protected override void PopulateOptions() { var auto = new ArrayParameterOption <uint?>(null, "Auto"); Options.Add(auto); SelectedOption = auto; CameraCapturePropertyRange range = PhotoCaptureDevice.GetSupportedPropertyRange(Device.SensorLocation, ParameterId); object currentValue = Device.GetProperty(ParameterId); uint[] standardValues = { 100, 200, 400, 800, 1600, 3200 }; var min = (uint)range.Min; var max = (uint)range.Max; foreach (uint isoValue in standardValues) { if (isoValue >= min && isoValue <= max) { string name = string.Format("ISO {0}", isoValue); var option = new ArrayParameterOption <uint?>(isoValue, name); Options.Add(option); if (isoValue.Equals(currentValue)) { SelectedOption = option; } } } }
// Override method for adjusting exposure time. public async void set_focus(double focus_val, int exposure_time) { // Set exposure time. try { _camera.SetProperty(KnownCameraPhotoProperties.ExposureTime, exposure_time * 1000); } catch (Exception err) { MessageBox.Show(err.ToString()); } focus_busy = true; try { CameraCapturePropertyRange range = PhotoCaptureDevice.GetSupportedPropertyRange(CameraSensorLocation.Back, KnownCameraGeneralProperties.ManualFocusPosition); double value = (UInt32)range.Min + (focus_val / 100.0) * ((UInt32)range.Max - (UInt32)range.Min); focus_min = (UInt32)range.Min; focus_max = (UInt32)range.Max; _camera.SetProperty(KnownCameraGeneralProperties.ManualFocusPosition, (UInt32)value); } // catch (Exception err) { MessageBox.Show(err.ToString()); } await _camera.FocusAsync(); focus_busy = false; }
protected override void PopulateOptions() { var auto = new ArrayParameterOption <uint?>(null, "Auto"); Options.Add(auto); CameraCapturePropertyRange times = PhotoCaptureDevice.GetSupportedPropertyRange(Device.SensorLocation, KnownCameraPhotoProperties .ExposureTime); var currentValue = (uint?)Device.GetProperty(ParameterId); uint[] standardValues = { 2000, 1000, 500, 250, 125, 60, 30, 15, 8, 4, 2, 1 }; var min = (uint)times.Min; var max = (uint)times.Max; foreach (uint timeValue in standardValues) { uint microSeconds = 1000000 / timeValue; if (microSeconds >= min && microSeconds <= max) { string name = string.Format("1 / {0} s", timeValue); var option = new ArrayParameterOption <uint?>(microSeconds, name); Options.Add(option); if (currentValue == microSeconds) { SelectedOption = option; } } } }
/// <summary> /// Reads supported exposure time values from Parameter.Device and populates /// ArrayParameter.Options accordingly. Sets the SelectedOption as well. /// /// Exposure time auto value is set by setting the value in PhotoCaptureDevice API to /// null, therefore the separate handling for option "Auto". /// </summary> protected override void PopulateOptions() { ArrayParameterOption option = new ArrayParameterOption(null, "Auto", "Assets/Icons/overlay.exposuretime.auto.png"); ArrayParameterOption selectedOption = option; Options.Add(option); CameraCapturePropertyRange range = PhotoCaptureDevice.GetSupportedPropertyRange(Device.SensorLocation, KnownCameraPhotoProperties.ExposureTime); object value = Device.GetProperty(PropertyId); // UInt32[] standardValues = { /* 16000, 8000, 4000,*/ 2000, 1000, 500, 250, 125, 60, 30, 15, 8, 4, 2 }; UInt32[] standardValues = { 16666, 16000, 8000, 4000, 2000, 1000, 500, 250, 125, 60, 30, 15, 8, 4, 2 }; UInt32 min = (UInt32)range.Min; UInt32 max = (UInt32)range.Max; System.Diagnostics.Debug.WriteLine(String.Format("Exposure time range (min {0}, max {1})", min, max)); foreach (UInt32 i in standardValues) { UInt32 usecs = 1000000 / i; if (usecs >= min && usecs <= max) { option = new ArrayParameterOption(usecs, "1 / " + i.ToString() + " s", "Assets/Icons/overlay.exposuretime." + i.ToString() + ".png"); Options.Add(option); if (selectedOption == null && usecs.Equals(value)) { selectedOption = option; } } } // Expsoure times of 1 second and over are possible in some devices. UInt32 microseconds = 1000000; // second in microseconds while (microseconds <= max) { UInt32 usecs = microseconds / 1000000; option = new ArrayParameterOption(microseconds, usecs.ToString() + " s", "Assets/Icons/overlay.exposuretime." + usecs.ToString() + "s.png"); Options.Add(option); if (selectedOption == null && usecs.Equals(value)) { selectedOption = option; } microseconds *= 2; } SelectedOption = selectedOption; }
public static UInt32 GetISO(UInt32 preferredISO, CameraSensorLocation loc) { CameraCapturePropertyRange isoRange = PhotoCaptureDevice.GetSupportedPropertyRange(loc, KnownCameraPhotoProperties.Iso); Nullable <UInt32> selectedISO = null; foreach (UInt32 standardISO in STANDARD_ISO_VALUES) { if (standardISO >= (UInt32)isoRange.Min && standardISO <= (UInt32)isoRange.Max && standardISO == preferredISO) { selectedISO = preferredISO; break; } } return(selectedISO.HasValue ? (UInt32)selectedISO : (UInt32)isoRange.Max); }