Opening and Handling Devices: Modify Device Properties

This source code snippet illustrates how video capture device properties can be modified.
Language:.NET C#/Visual Basic
Version:3.0.3
Released on:April 7, 2005
Author:IC Imaging Control Support Department
Requirements:IC Imaging Control >2.1
Camera, converter or grabber with WDM Stream Class drivers.

The window of the resulting application looks as follows:

The dialog window of the sample application.

IC Imaging Control offers the VCDSimpleProperty class to adjust video capture device settings:

[C#]
private VCDSimpleProperty vcdProp = null;
[VB.NET]
Private VCDProp As VCDSimpleProperty

The instance of VCDSimpleProperty class is created by Form1_load:

[C#]
vcdProp = new VCDSimpleProperty( icImagingControl1.VCDPropertyItems );
[VB.NET]
VCDProp = VCDSimpleModule.GetSimplePropertyContainer(ICImagingControl1.VCDPropertyItems)

First of all, the program checks whether the device provides an automatic mode for the parameter "Brightness". If it does not, the dialog's checkbox Auto (chkBrightnessAuto.Enabled = False) is deactivated. If it does, the program explicitly switches it off (VCDProp.Automation(VCDID_Brightness = False):

[C#]
if( !vcdProp.AutoAvailable( VCDIDs.VCDID_Brightness ) )
{
    chkBrightnessAuto.Enabled = false;
}
else
{
    vcdProp.Automation[VCDIDs.VCDID_Brightness] = false;
}
[VB.NET]
If Not VCDProp.AutoAvailable(VCDIDs.VCDID_Brightness) Then
    BrightnessAutoCheckBox.Enabled = False
Else
    VCDProp.Automation(VCDIDs.VCDID_Brightness) = False
End If

Secondly, the program checks whether the device allows the parameter "Brightness" to be manually adjusted. If it does not, the dialog's slider Brightness (sldBrightness.Enabled = False ) is deactivated. If it does, the program determines the smallest and highest value provided by the device (VCDProp.RangeMin and VCDProp.RangeMax) and the current value (VCDProp.RangeValue). The program then uses these values to initialize sldBrightness and lblBrightnessValue:

[C#]
if( !vcdProp.Available( VCDIDs.VCDID_Brightness ) )
{
    sldBrightness.Enabled = false;
}
else
{
    sldBrightness.Minimum = vcdProp.RangeMin(VCDIDs.VCDID_Brightness);
    sldBrightness.Maximum = vcdProp.RangeMax(VCDIDs.VCDID_Brightness);
    sldBrightness.Value = vcdProp.RangeValue[VCDIDs.VCDID_Brightness];
    sldBrightness.TickFrequency = (sldBrightness.Maximum - sldBrightness.Minimum) / 10;
    lblBrightnessValue.Text = sldBrightness.Value.ToString();
}
[VB.NET]
If Not VCDProp.Available(VCDIDs.VCDID_Brightness) Then
    BrightnessTrackBar.Enabled = False
Else
    BrightnessTrackBar.Enabled = True
    BrightnessTrackBar.Minimum = VCDProp.RangeMin(VCDIDs.VCDID_Brightness)
    BrightnessTrackBar.Maximum = VCDProp.RangeMax(VCDIDs.VCDID_Brightness)
    BrightnessTrackBar.Value = VCDProp.RangeValue(VCDIDs.VCDID_Brightness)
    BrightnessTrackBar.TickFrequency = (BrightnessTrackBar.Maximum - BrightnessTrackBar.Minimum) / 10
    BrightnessValueLabel.Text = BrightnessTrackBar.Value
End If

When the user modifies the slider's position of sldBrightness, the program writes the new "Brightness" value into the device (VCDProp.RangeValue(VCDID_Brightness)) and displays it in the dialog ( lblBrightnessValue):

[C#]
private void sldBrightness_Scroll(object sender, System.EventArgs e)
{
    vcdProp.RangeValue[VCDIDs.VCDID_Brightness] = sldBrightness.Value;
    lblBrightnessValue.Text = sldBrightness.Value.ToString();
}
[VB.NET]
Private Sub BrightnessTrackBar_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BrightnessTrackBar.Scroll
    VCDProp.RangeValue(VCDIDs.VCDID_Brightness) = BrightnessTrackBar.Value
    BrightnessValueLabel.Text = VCDProp.RangeValue(VCDIDs.VCDID_Brightness)
End Sub

When the user clicks the check box Auto (chkBrightnessAuto ) to activate the automatic mode, the program enables this mode of the device (VCDProp.Automation(VCDID_Brightness) = True) and deactivates the slider (sldBrightness.Enabled = False):

[C#]
private void chkBrightnessAuto_CheckedChanged(object sender, System.EventArgs e)
{
    vcdProp.Automation[VCDIDs.VCDID_Brightness] = chkBrightnessAuto.Checked;
    sldBrightness.Enabled = !chkBrightnessAuto.Checked;
}
[VB.NET]
Private Sub BrightnessAutoCheckBox_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BrightnessAutoCheckBox.CheckedChanged
    VCDProp.Automation(VCDIDs.VCDID_Brightness) = BrightnessAutoCheckBox.Checked
    BrightnessTrackBar.Enabled = Not BrightnessAutoCheckBox.Checked
End Sub

The adjustment of other device settings follows the above scheme. There is a list of settings offered by IC Imaging Control in the User's Guide.

Related Source Code Samples

Disclaimer
The source code that appears in the IC Imaging Control Source Code Library is indented for educational purposes only. The Imaging Source Europe GmbH, the manufacturer of IC Imaging Control, does not assume any kind of warranty expressed or implied, resulting from the use of the content of this page.

This site is part of The Imaging Source Network. Other sites include Company Portal, Image Processing, Astronomy Cameras, Astronomy Cameras Blog, Blog caméras d'astronomie, Astronomy Cameras Competition, TX Text Control, LiveDocx, phpLiveDocx and Forums.