
| Language: | Visual Basic 6 |
| 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 following programming example (Visual Basic) illustrates how you can use IC Imaging Control to overlay a live image data stream with a movable crosshair. Additionally, the cross' current position is displayed.
The sample application's window looks as follows:

The program starts by activating a built-in dialog to select a device (.ShowDeviceSettingsDialog). At the end of the function (Form_Load()), the device's live image data stream is displayed using .LiveStart. In preparation, there are two additional steps: Firstly, the overlay mode has to be activated (.OverlayBitmap.Enable) and the status variable dragging has to be set to False. We are going to use this status variable to indicate that the mouse button is kept pressed down:
Dim dragging As Boolean Private Sub Form_Load() ICImagingControl1.ShowDeviceSettingsDialog If Not ICImagingControl1.DeviceValid Then Unload Me Exit Sub End If ICImagingControl1.OverlayBitmap.Enable = True ICImagingControl1.LiveStart dragging = False End Sub
A crosshair consist of two red lines with an attached blue text, indicating the cross' position (see image on the right). .OverlayBitmap.DrawLine draws the lines, while .OverlayBitmap.DrawText generates the text:
Private Sub DisplayCrosshairs(XPos As Integer, YPos As Integer) ICImagingControl1.OverlayBitmap.DrawLine vbRed, XPos, YPos - 10, XPos, YPos + 10 ICImagingControl1.OverlayBitmap.DrawLine vbRed, XPos - 10, YPos, XPos + 10, YPos ICImagingControl1.OverlayBitmap.DrawText vbBlue, XPos + 3, YPos + 2, XPos & "," & YPos End Sub
There are two factors determining the crosshairs' position: the mouse's movement and it's button state. The following three event handlers perform the necessary processing. When the user clicks into the image, the program removes the "old" crosshair, filling the overlay bitmap with the transparent color .DropOutColor. DisplayCrosshairs XPos, YPos draws a new crosshair at the mouse's position:
Private Sub ICImagingControl1_MouseDown(ByVal Button As Long, ByVal Shift As Long, ByVal XPos As Integer, ByVal YPos As Integer) If Not Shift And vbShiftMask Then ICImagingControl1.OverlayBitmap.Fill ICImagingControl1.OverlayBitmap.DropOutColor End If DisplayCrosshairs XPos, YPos dragging = True End Sub
When the user moves the mouse, while pressing the mouse button, the program removes the "old" crosshair, filling the overlay bitmap with the transparent color .DropOutColor. DisplayCrosshairs XPos, YPos draws a new crosshair at the mouse's position:
Private Sub ICImagingControl1_MouseMove(ByVal Button As Long, ByVal Shift As Long, ByVal XPos As Integer, ByVal YPos As Integer) If dragging Then If Not Shift And vbShiftMask Then ICImagingControl1.OverlayBitmap.Fill ICImagingControl1.OverlayBitmap.DropOutColor End If DisplayCrosshairs XPos, YPos End If End Sub
Releasing the mouse button leads to a reset of the status variable dragging to False:
Private Sub ICImagingControl1_MouseUp(ByVal Button As Long, ByVal Shift As Long, ByVal XPos As Integer, ByVal YPos As Integer) dragging = False End Sub
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.