顯示現場視頻: 圖形疊加:可移動坐標準心

使用IC Imaging Control在視頻上加入可移動坐標準心。
語言:Visual Basic 6
版本:3.0.3
发布于:2005年4月7日
作者:IC Imaging Control 技術支持部
需求:IC Imaging Control >2.1
由WDM數據流類驅動程序驅動的相機、視頻轉換器或圖像採集卡

這個例子介紹的是如何使用IC Imaging Control在視頻上加入可移動坐標準心。

示例程序窗口如圖所示:

The dialog window of the sample application.

程序開始後首先調用對話框(.ShowDeviceSettingsDialog)用於選擇設備。 Form_Load()結尾處.LiveStart將顯示設備傳來的現場視頻。 準備工作有兩步:第一,開啟疊加模式(.OverlayBitmap.Enable)。第二,將dragging狀態設為False, 該變量將被用於指示鼠標左鍵是否處於按下狀態。

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

坐標準心由兩條紅色線段和一副藍色坐標值構成。 .OverlayBitmap.DrawLine用於劃線,.OverlayBitmap.DrawText生成坐標:

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

決定準心位置的有兩個因素:鼠標的運動及其按鍵狀態。 用戶點擊畫面,程序將刪除舊的坐標點,給疊加層bitmap填入透明色.DropOutColor。 DisplayCrosshairs XPos, YPos將為鼠標畫出新的準心:

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

用戶按住左鍵移動鼠標時,程序將刪除舊的坐標點,給疊加層bitmap填入透明色. DropOutColor. DisplayCrosshairs XPos, YPos將為鼠標畫出新的準心:

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

放開鼠標將把狀態變量dragging重設為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

相關源代碼示例

責任聲明
IC Imaging Control源代碼庫中的所有代碼均只用於教學目的,The Imaging Source Europe GmbH作為IC Imaging Control的開發製造商,不對任何由於使用本文或其中源代碼所產生的後果承擔責任。

该网站为The Imaging Source网络的一部分。其它的站点包括 公司, Imaging, 天文相機, Astronomy Cameras Blog, Blog caméras d'astronomie, 天文相機有獎競答, TX Text Control, LiveDocx, phpLiveDocxForum.