IC Imaging Control ActiveX

Basic Use of VCD Properties

Basic Use of VCD Properties

This chapter illustrates the basic functionality of the VCDProperties. It shows you how to retrieve interfaces which allow you to manipulate elements, such as the value or the automation state of a property.

Introduction

This sample uses the "Brightness" property to demonstrate how the properties are organized and how they are accessed. First, the VCDPropertyItem for "Brightness" is retrieved from the VCDPropertyItems collection. Then a switch and a range interface is retrieved from the respective elements of this VCDPropertyItem. The switch interface is used to turn the automation state of this property on and off. The range interface is used to manipulate the value of this property.

The source code for this sample program can be found in the samples\VB6\VCD Simple sample source directory.

Creating the Project

Create a new project and add IC Imaging Control to the form. Before you run the program, select the video device, input and video format as shown in the First Steps in Visual Basic 6 chapter. Alternatively, run the program without selecting a device. In this case, the program shows the device selection dialog that ships with IC Imaging Control. If you close this dialog without selecting a device, the program displays an error message and terminates.

In order to specify a certain property, the module VCDPropertyID.bas must be added to the project. It can be found in the samples\VB6\common directory. The module contains the IDs that are needed to specify a property. To add the module to your project select Project from the menu and select Add Module. In the dialog, click the Existing tab and browse to the samples\VB6\common folder. Select the file VCDPropertyID.bas and click the Open button. The module is now part of your project.

Now add a check box and a slider (or 'trackbar') to the form. Name the check box chkBrightnessAuto and the slider sldBrightness.

Retrieving a VCDPropertyItem

After a valid video capture device has been selected, the VCDPropertyItem for "Brightness" is retrieved:

' Get the Brightness property item
Dim Brightness As VCDPropertyItem
Set Brightness = ICImagingControl1.VCDPropertyItems.FindItem(VCDID_Brightness)

Just declare a variable of type VCDPropertyItem and use the VCDPropertyItems.FindItem method to assign the appropriate property. The property item that should be retrieved must be specified by its ID as mentioned above. In this case, it is VCDID_Brightness for the "Brightness" property item.

Retrieving Interfaces and Initialize the Controls

Properties consist of one or more elements like the value, automation state, one push operation and further parameters, if supported. To manipulate a property, interfaces are used. They can be retrieved from the elements of a property item. Declare 2 global variables that will hold the interfaces to the value and the automation state:

Dim BrightnessRange As VCDRangeProperty
Dim BrightnessSwitch As VCDSwitchProperty

The following code shows you how to actually retrieve a switch and a range interface and how to get their current states in order to initialize the associated user controls.

If Not Brightness Is Nothing Then
    ' Get interfaces which allow to manipulate the property.
    Set BrightnessRange = Brightness.Elements.FindInterface(VCDElement_Value + ":" + VCDInterface_Range)
    Set BrightnessSwitch = Brightness.Elements.FindInterface(VCDElement_Auto + ":" + VCDInterface_Switch)
End If

The VCDPropertyElements.FindInterface method of the property item is used to retrieve an interface. As described above, a property item consists of one or more elements which provide one or more interfaces. Therefore, the element ID and the interface ID have to be specified when calling the VCDPropertyElements.FindInterface method.

Now that the we have the interfaces, the user controls can be initialized. The following code shows you how this is done:

' Initialize the slider with the current range and value of the
' Brightness property.
 If Not BrightnessRange Is Nothing Then
     sldBrightness.Min = BrightnessRange.RangeMin
     sldBrightness.Max = BrightnessRange.RangeMax
     sldBrightness.Value = BrightnessRange.Value
     sldBrightness.Enabled = True
 Else
     sldBrightness.Enabled = False
 End If

' Initialize the check box with the current automation state
' of the Brightness property.
 If Not BrightnessSwitch Is Nothing Then
     chkBrightnessAuto.Enabled = True
     If BrightnessSwitch.Switch Then
         chkBrightnessAuto.Value = 1
         sldBrightness.Enabled = False
     Else
         chkBrightnessAuto.Value = 0
         sldBrightness.Enabled = True
     End If
 Else
     chkBrightnessAuto.Enabled = False
 End If

As the code above shows, the interface classes let you easily access the elements of a property item.

Manipulating the elements of a Property

In this final step, we want to show you how to use the interfaces to manipulate a property. Add a Click event for the check box and a Scroll event for the slider. The check box toggles the automation state of the "Brightness" property. The code looks as follows:

Private Sub chkBrightnessAuto_Click()
On Error Resume Next
    ' Set the automation state of the Brightness property according to
    ' the switch.
    BrightnessSwitch.Switch = chkBrightnessAuto.Value
    If chkBrightnessAuto.Value = 1 Then
        sldBrightness.Enabled = False
    Else
        sldBrightness.Enabled = True
    End If
End Sub

The code above just assigns the current state of the check box to the automation element of the "Brightness" property. Additionally, the slider will be disabled, if the automation state is on.

The code for the Scroll event of the slider is even simpler:

Private Sub sldBrightness_Scroll()
On Error Resume Next
    ' value to the interface
    BrightnessRange.Value = sldBrightness.Value
End Sub

Now you can run the program and manipulate the "Brightness" property, using the slider and the check box.

<< Programmer's Guide

Get in touch with us


About The Imaging Source

Established in 1990, The Imaging Source is one of the leading manufacturers of industrial cameras, frame grabbers and video converters for production automation, quality assurance, logistics, medicine, science and security.

Our comprehensive range of cameras with USB 3.1, USB 3.0, USB 2.0, GigE interfaces and other innovative machine vision products are renowned for their high quality and ability to meet the performance requirements of demanding applications.

Automated Imaging Association ISO 9001:2015 certified

Contact us