This chapter shows you how to use the scroll and zoom capabilities of IC Imaging Control.
The source code for this sample program can be found in the samples\VB6\Scroll And Zoom directory.
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 making a selection, the program displays an error message and terminates.
Now add 2 buttons to the form and label them Start and Stop. Name the buttons cmdStart and cmdStop respectively.
Add a call to ICImagingControl.LiveStart method. In addition, a red rectangle is drawn around the whole image to visualize its perimeter:
Add a call to ICImagingControl.LiveStop:
Now add two check boxes and name them chkDisplayDefault and chkScrollbarsEnable. Label them Default window size and Scrollbars respectively. They will be used to set the LiveDisplayDefault and the ScrollBarsEnabled properties.
Also add a slider control to the form and name it sldZoom. It will be used to set the LiveDisplayZoomFactor property. In the property window of the slider, set the range of the slider from 1 to 30. The slider's value will be divided by 10, before it is passed to the LiveDisplayZoomFactor property. This allows a zoom from 10% up to 300%.
Now add 2 buttons to the form and label them Device and Settings. Name the buttons cmdDevice and cmdImageSettings respectively. Add the button handler functions:
Enhance the cmdDevice_Click procedure to setup the check boxes and the slider control:
The check box chkDisplayDefault is used to toggle the LiveDisplayDefault property. Add a chkDisplayDefault_Click function to the form's source code. In this function, the current value of the chkDisplayDefault check box is retrieved and LiveDisplayDefault is set. Setting the LiveDisplayDefault property changes the value of the LiveDisplayZoomFactor property. Therefore, the value for the sldZoom slider control is updated to the LiveDisplayZoomFactor property value. Also, the slider control will be disabled, if the LiveDisplayDefault property returns True. If the LiveDisplayDefault property returns False, the slider control will be enabled, because now the zoom factor can be set.
The check box chkScrollBarsEnable is used to enable and disable the scrollbars. Add a chkScrollbarsEnable_Click function to the form's source code. In this function, the current value of the chkScrollbarsEnable check box is retrieved and ScrollBarsEnabled is set. This allows you to show or hide the scrollbars in IC Imaging Control's window. Disabling the scrollbars will reset the live displays window position to 0/0.
The Slider sldZoom is used to set the zoom factor of the live video image. Add a sldZoom_Scroll function to the form's source code, to handle the change of the slider control. Because the range of the slider has been set from 1 to 30, the slider's value has to be divided by 10, before it is passed to LiveDisplayZoomFactor.
Run the program. You can now start and stop the live image by clicking on the respective buttons. You can enable or disable the LiveDisplayDefault property and see, how IC Imaging Control reacts. You can also show and hide the scrollbars and zoom the live video.
If the scrollbar values are changed, the functions OnHScroll and OnVScroll are called. The current scroll position is passed to these methods.
Add a new label to the form and name it lblScrollPosition. This new label is used to display the current scroll position. Also add the OnHScroll and OnVScroll event functions to the form's source code. Enhance both functions as follows:
Now, the current scroll position is displayed in the new label, each time, you scroll the live display with the scroll bars.