IC Imaging Control ActiveX

Scroll and Zoom

Scroll and Zoom

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.

Setting up the Project

image

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:

Private Sub cmdStart_Click()
    ICImagingControl1.LiveStart
    With ICImagingControl1

        ' Draw a rectangle around the whole image to visualize its perimeter.
        .OverlayBitmap.Enable = True
        .OverlayBitmap.DrawLine RGB(255, 0, 0), 0, 0, .ImageWidth - 1, 0
        .OverlayBitmap.DrawLine RGB(255, 0, 0), .ImageWidth - 1, 0, .ImageWidth - 1, .ImageHeight - 1
        .OverlayBitmap.DrawLine RGB(255, 0, 0), .ImageWidth - 1, .ImageHeight - 1, 0, .ImageHeight - 1
        .OverlayBitmap.DrawLine RGB(255, 0, 0), 0, 0, 0, .ImageHeight
        .OverlayBitmap.DrawText RGB(255, 0, 0), 5, 5, "Scroll and Zoom Sample"
    End With
End Sub

Add a call to ICImagingControl.LiveStop:

Private Sub cmdStop_Click()
    ICImagingControl1.LiveStop
End Sub

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:

Private Sub cmdImageSettings_Click()
    ICImagingControl1.ShowPropertyDialog
End Sub

Enhance the cmdDevice_Click procedure to setup the check boxes and the slider control:

Private Sub cmdDevice_Click()
    If ICImagingControl1.DeviceValid Then
        If ICImagingControl1.LiveVideoRunning Then
            ICImagingControl1.LiveStop
        End If
    End If

    ICImagingControl1.ShowDeviceSettingsDialog

    If Not ICImagingControl1.DeviceValid Then
        cmdStart.Enabled = False
        cmdStop.Enabled = False
        cmdImageSettings.Enabled = False
        chkDisplayDefault.Enabled = False
        chkScrollbarsEnable.Enabled = False
        sldZoom.Enabled = False
        lblZoom.Enabled = False
    Else
        cmdStart.Enabled = True
        cmdStop.Enabled = True
        cmdImageSettings.Enabled = True
        chkDisplayDefault.Enabled = True
        chkScrollbarsEnable.Enabled = True
        sldZoom.Enabled = True
        lblZoom.Enabled = True

        ICImagingControl1.LiveDisplayDefault = False
        chkDisplayDefault.Value = 0

        If ICImagingControl1.ScrollbarsEnabled = True Then
            chkScrollbarsEnable.Value = 1
        Else
            chkScrollbarsEnable.Value = 0
        End If

        ' Enable or disable the slider for the zoom factor, depending
        ' on the LiveDisplayDefault property.
        sldZoom.Enabled = Not ICImagingControl1.LiveDisplayDefault
        sldZoom.Value = ICImagingControl1.LiveDisplayZoomFactor * 10
        sldZoom_Scroll
    End If
End Sub

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.

Private Sub chkDisplayDefault_Click()
    If chkDisplayDefault.Value = 1 Then
        ICImagingControl1.LiveDisplayDefault = True
    Else
        ICImagingControl1.LiveDisplayDefault = False
    End If
    sldZoom.Enabled = Not ICImagingControl1.LiveDisplayDefault
    sldZoom.Value = ICImagingControl1.LiveDisplayZoomFactor * 10
    lblZoomPercent.Caption = Str(sldZoom.Value * 10) + ""
End Sub

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.

Private Sub chkScrollbarsEnable_Click()
   If chkScrollbarsEnable.Value = 1 Then
        ICImagingControl1.ScrollbarsEnabled = True
    Else
        ICImagingControl1.ScrollbarsEnabled = False
    End If
End Sub

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.

Private Sub sldZoom_Scroll()
    If ICImagingControl1.LiveDisplayDefault = False Then
       ICImagingControl1.LiveDisplayZoomFactor = sldZoom.Value / 10
       lblZoomPercent.Caption = Str(sldZoom.Value * 10) + ""
    Else
        MsgBox "The zoom factor can only be set" + Chr(13) + _
               "if LiveDisplayDefault returns False!"
    End If
End Sub

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:

Private Sub ICImagingControl1_OnHScroll(ByVal XPos As Long, ByVal YPos As Long)
    lblScrollPosition.Caption = Str(XPos) + "/" + Str(YPos)
End Sub
Private Sub ICImagingControl1_OnVScroll(ByVal XPos As Long, ByVal YPos As Long)
    lblScrollPosition.Caption = Str(XPos) + "/" + Str(YPos)
End Sub

Now, the current scroll position is displayed in the new label, each time, you scroll the live display with the scroll bars.

<< 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