#

UWP: Integrierte Kamera Controller einstellen

 

Mit diesem Code werden alle internen Einstellungen einer Web-Kamera oder USB Kamera an Windows 10 ermittelt und in eine Auswahl zum einstellen geladen.

Sobald man eine Einstellung auswählt, kann man mit einem Schieberegler die Eigenschaft einstellen.

Im Beispiel ist das die Brightness, Contrast, Exposure, Focus, Pan, WhiteBalance und Zoom der internen Regler einer Logitech B910 WebCam

 

 

Zentrales Element ist in diesem Fall die internen Regler einer Web-Kamera      

        MediaDeviceControl _control;

        MediaDeviceControlCapabilities _caps;

 

 

An der angeschlossenen Kamera wird geprüft ob eine interne Einstellung möglich ist und wenn diese unterstützt wird, dann wird diese zur Auswahl angefügt.

if (_mediaCapture.VideoDeviceController.Brightness.Capabilities.Supported) combo_Controllers.Items.Add("Brightness");

 

 

Beim Auswählen einer Einstellung im Dropdown-Auswahl-Element wird dann der MediaDeviceController ausgewählt

if(sController=="Brightness") _control = _mediaCapture.VideoDeviceController.Brightness;

 

Und dann die Möglichkeiten ermittelt

_caps = _control.Capabilities;

 

 

Und wenn vorhanden warden diese auf den Schieberegler übertragen

//----< set Slider >----

                slider_Modify.Visibility = Visibility.Visible;

                slider_Modify.Maximum = _caps.Max;

                slider_Modify.Minimum = _caps.Min;

                double val = 0;

                _control.TryGetValue(out val);

                slider_Modify.Value = val;

                //----</ set Slider >----

 

                //< set Auto-Control >

                if (_caps.AutoModeSupported)

                {

                    cbxAuto.Visibility = Visibility.Visible;

                    bool isAuto;

                    _control.TryGetAuto(out isAuto);

                    cbxAuto.IsChecked = isAuto;

                }

 

 

 

Zum Abschluss wird beim Verändern des Schiebereglers der Wert übernommen und direkt in die angeschlossene USB Kamera übertragen

double val = slider_Modify.Value;

_control.TrySetValue(val);

 

 

 

Video Anleitung

 

Im Projekt wurde der Code in eine UWP Anwendung eingefügt direkt in der Mainpage

 

 

 

Kompletter C# Code zum Einstellen der Anwendung.

 

 

        private void btnOptions_Click(object sender, RoutedEventArgs e)

        {

            //----------------< btnOptions_Click() >----------------

            if(combo_Controllers.Visibility==Visibility.Visible )

            {

                combo_Controllers.Visibility = Visibility.Collapsed ;

                cbxAuto.Visibility = Visibility.Collapsed;

                slider_Modify.Visibility = Visibility.Collapsed;

            }

            else

            {

                combo_Controllers.Visibility = Visibility.Visible;

                cbxAuto.Visibility = Visibility.Visible;

                slider_Modify.Visibility = Visibility.Visible;

                init_Controllers();

            }

            //----------------</ btnOptions_Click() >----------------

        }

 

 

        private void init_Controllers()

        {

            //----------------< init_Controllers() >----------------

            combo_Controllers.Items.Clear();

            combo_Controllers.Visibility = Visibility.Visible;

            lblApp.Visibility = Visibility.Collapsed;

            //--< check Controlles and add to List >--

            if (_mediaCapture.VideoDeviceController.Brightness.Capabilities.Supported) combo_Controllers.Items.Add("Brightness");

            if (_mediaCapture.VideoDeviceController.Contrast.Capabilities.Supported) combo_Controllers.Items.Add("Contrast");

            if (_mediaCapture.VideoDeviceController.Exposure.Capabilities.Supported) combo_Controllers.Items.Add("Exposure");

            if (_mediaCapture.VideoDeviceController.Focus.Capabilities.Supported) combo_Controllers.Items.Add("Focus");

            if (_mediaCapture.VideoDeviceController.Hue.Capabilities.Supported) combo_Controllers.Items.Add("Hue");

            if (_mediaCapture.VideoDeviceController.Pan.Capabilities.Supported) combo_Controllers.Items.Add("Pan");

            if (_mediaCapture.VideoDeviceController.WhiteBalance.Capabilities.Supported) combo_Controllers.Items.Add("WhiteBalance");

            if (_mediaCapture.VideoDeviceController.Zoom.Capabilities.Supported) combo_Controllers.Items.Add("Zoom");

            //--</ check Controlles and add to List >--

 

            if (combo_Controllers.Items.Count > 0)

            {

                combo_Controllers.SelectedIndex = 0;

            }

            else

            {

                combo_Controllers.Visibility = Visibility.Collapsed;

            }

            //----------------</ init_Controllers() >----------------

        }

 

        private void combo_Controllers_SelectionChanged(object sender, SelectionChangedEventArgs e)

        {

            //----------------< combo_Controllers_SelectionChanged() >----------------

 

            ComboBox ctlComboBox = sender as ComboBox;

            //< check >

            if (ctlComboBox.SelectedValue==null)

            {

                return;

            }

            //</ check >

 

            string sController = ctlComboBox.SelectedValue.ToString();

 

            //< check Selection >

            //*and set _Controller

            if(sController=="Brightness") _control = _mediaCapture.VideoDeviceController.Brightness;

            else if (sController == "Contrast") _control = _mediaCapture.VideoDeviceController.Contrast ;

            else if (sController == "Exposure") _control = _mediaCapture.VideoDeviceController.Exposure;

            else if (sController == "Focus") _control = _mediaCapture.VideoDeviceController.Focus;

            else if (sController == "Hue") _control = _mediaCapture.VideoDeviceController.Hue;

            else if (sController == "Pan") _control = _mediaCapture.VideoDeviceController.Pan;

            else if (sController == "WhiteBalance") _control = _mediaCapture.VideoDeviceController.WhiteBalance;

            else if (sController == "Zoom") _control = _mediaCapture.VideoDeviceController.Zoom;

            //</ check Selection >

 

            //< set controls-Elemtens >

            check_Controller(_control);

            //</ set control-Elements >

            //----------------</ combo_Controllers_SelectionChanged() >----------------

        }

 

        #region Camera_Device_Controller

 

 

        MediaDeviceControl _control;

        MediaDeviceControlCapabilities _caps;

 

        private void check_Controller(MediaDeviceControl video_Device_Controller)

        {

            //----------------< check_Controller() >----------------

            //*get Brightness Controller of Webcam, internal controller

            //< get Control >

            //_control = _mediaCapture.VideoDeviceController.Brightness;

            _caps = _control.Capabilities;

            //</ get Control >

            if (_caps.Supported == true)

            {

               

                //----< set Slider >----

                slider_Modify.Visibility = Visibility.Visible;

                slider_Modify.Maximum = _caps.Max;

                slider_Modify.Minimum = _caps.Min;

                double val = 0;

                _control.TryGetValue(out val);

                slider_Modify.Value = val;

                //----</ set Slider >----

 

                //< set Auto-Control >

                if (_caps.AutoModeSupported)

                {

                    cbxAuto.Visibility = Visibility.Visible;

                    bool isAuto;

                    _control.TryGetAuto(out isAuto);

                    cbxAuto.IsChecked = isAuto;

                }

                else

                {

                    cbxAuto.Visibility = Visibility.Collapsed;

                }

                //</ set Auto-Control >

            }

            else

            {

                //< not supported >

                slider_Modify.Visibility = Visibility.Collapsed;

                cbxAuto.Visibility = Visibility.Collapsed;

                //</ not supported >

            }

            //----------------</ check_Controller() >----------------

        }

 

        private void slider_Modify_ValueChanged(object sender, Windows.UI.Xaml.Controls.Primitives.RangeBaseValueChangedEventArgs e)

        {

            //----------------< slider_Modify_ValueChanged() >----------------

            if (_caps.Supported == true)

            {

                double val = slider_Modify.Value;

                _control.TrySetValue(val);

            }

            //----------------</ slider_Modify_ValueChanged() >----------------

        }

 

        private void cbxAuto_Click(object sender, RoutedEventArgs e)

        {

            //< set auto >

            _control.TrySetAuto((bool)cbxAuto.IsChecked);

            //</ set auto >

        }

 

        #endregion /Camera_Device_Controller

 

 

 

Xaml Controls:

Ein Button zum Ein/Ausschalten der Optionen

Ein Slider zum Einstellen der Werte und eine Checkbox, welche optional die Auto-Funktion ermöglicht

Eine Combobox zum Auswählen des Einstellungscontrollers

       <Button x:Name="btnOptions" Click="btnOptions_Click" HorizontalAlignment="Right" VerticalAlignment="Stretch"   Grid.Row="1" Width="45"

               TabIndex="0"

               PointerEntered="btnOptions_PointerEntered" PointerExited="btnOptions_PointerExited" Background="LightGray"   Opacity="0.5"   >

            <SymbolIcon Symbol="SwitchApps"   ></SymbolIcon>   

        </Button>

        <CheckBox x:Name="cbxAuto" Content="Auto" HorizontalAlignment="left" VerticalAlignment="Bottom"  Margin="5,0,0,30" Grid.Row="0" Click="cbxAuto_Click" Visibility="Collapsed" />

        <Slider x:Name="slider_Modify" ValueChanged="slider_Modify_ValueChanged"  HorizontalAlignment="Stretch"  VerticalAlignment="Bottom"     Grid.Row="0" Visibility="Collapsed"/>

       

        <ComboBox x:Name="combo_Controllers" HorizontalAlignment="Left"  VerticalAlignment="Stretch"   Grid.Row="1" Visibility="Collapsed" Padding="4,0,0,0" Margin="0" SelectionChanged="combo_Controllers_SelectionChanged"/>

 

 

Mobile

.

0123movie.net