我有一個webcam 簡單程式 現在想加入QR code實時解讀~
找了很多網站都沒有 例可以參考~
現附上一個webcam progarm
謝謝~
Option Explicit
Const WS_CHILD = &H40000000
Const WS_VISIBLE = &H10000000
Const WM_CAP_START As Long = &H400
Const WM_CAP_DRIVER_CONNECT As Long = WM_CAP_START + 10
Const WM_CAP_DLG_VIDEOFORMAT As Long = WM_CAP_START + 41
Const WM_CAP_SET_PREVIEW As Long = WM_CAP_START + 50
Const WM_CAP_SET_PREVIEWRATE As Long = WM_CAP_START + 52
Const WM_CAP_SET_SCALE As Long = WM_CAP_START + 53
Private Declare Function capCreateCaptureWindow Lib "avicap32.dll" Alias "capCreateCaptureWindowA" _
(ByVal lpszWindowName As String, ByVal dwStyle As Long, ByVal X As Long, ByVal Y As Long, _
ByVal nWidth As Long, ByVal nHeight As Long, ByVal hwndParent As Long, ByVal nID As Long) As Long
Private Declare Function SendMessageAsLong Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim CamVc1 As Long, ReCam As Long
Private Sub Form_Load()
'160x120:176x144:320x240:352x288:640x480 (建立CaptureWindow)
CamVc1 = capCreateCaptureWindow("Capture Windows", _
WS_CHILD Or WS_VISIBLE, 380, 40, 320, 240, Me.hwnd, 0)
If CamVc1 = 0 Then
Exit Sub
End If
ReCam = capDriverConnect(CamVc1, 0)
ReCam = capPreviewRate(CamVc1, 50) '每秒20張(=1000/20)
ReCam = capPreview(CamVc1, True)
Me.Caption = "Capture Windows"
End Sub
Function capDriverConnect(ByVal hCapWnd As Long, Optional ByVal i As Long = 0&) As Boolean
capDriverConnect = SendMessageAsLong(hCapWnd, WM_CAP_DRIVER_CONNECT, i, 0&)
End Function
Function capDlgVideoFormat(ByVal hCapWnd As Long) As Boolean
capDlgVideoFormat = SendMessageAsLong(hCapWnd, WM_CAP_DLG_VIDEOFORMAT, 0&, 0&)
End Function
Function capPreview(ByVal hCapWnd As Long, ByVal f As Boolean) As Boolean
capPreview = SendMessageAsLong(hCapWnd, WM_CAP_SET_PREVIEW, -(f), 0&)
End Function
Function capPreviewRate(ByVal hCapWnd As Long, ByVal wMS As Long) As Boolean
capPreviewRate = SendMessageAsLong(hCapWnd, WM_CAP_SET_PREVIEWRATE, wMS, 0&)
End Function
找了很多網站都沒有 例可以參考~
現附上一個webcam progarm
謝謝~
Option Explicit
Const WS_CHILD = &H40000000
Const WS_VISIBLE = &H10000000
Const WM_CAP_START As Long = &H400
Const WM_CAP_DRIVER_CONNECT As Long = WM_CAP_START + 10
Const WM_CAP_DLG_VIDEOFORMAT As Long = WM_CAP_START + 41
Const WM_CAP_SET_PREVIEW As Long = WM_CAP_START + 50
Const WM_CAP_SET_PREVIEWRATE As Long = WM_CAP_START + 52
Const WM_CAP_SET_SCALE As Long = WM_CAP_START + 53
Private Declare Function capCreateCaptureWindow Lib "avicap32.dll" Alias "capCreateCaptureWindowA" _
(ByVal lpszWindowName As String, ByVal dwStyle As Long, ByVal X As Long, ByVal Y As Long, _
ByVal nWidth As Long, ByVal nHeight As Long, ByVal hwndParent As Long, ByVal nID As Long) As Long
Private Declare Function SendMessageAsLong Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim CamVc1 As Long, ReCam As Long
Private Sub Form_Load()
'160x120:176x144:320x240:352x288:640x480 (建立CaptureWindow)
CamVc1 = capCreateCaptureWindow("Capture Windows", _
WS_CHILD Or WS_VISIBLE, 380, 40, 320, 240, Me.hwnd, 0)
If CamVc1 = 0 Then
Exit Sub
End If
ReCam = capDriverConnect(CamVc1, 0)
ReCam = capPreviewRate(CamVc1, 50) '每秒20張(=1000/20)
ReCam = capPreview(CamVc1, True)
Me.Caption = "Capture Windows"
End Sub
Function capDriverConnect(ByVal hCapWnd As Long, Optional ByVal i As Long = 0&) As Boolean
capDriverConnect = SendMessageAsLong(hCapWnd, WM_CAP_DRIVER_CONNECT, i, 0&)
End Function
Function capDlgVideoFormat(ByVal hCapWnd As Long) As Boolean
capDlgVideoFormat = SendMessageAsLong(hCapWnd, WM_CAP_DLG_VIDEOFORMAT, 0&, 0&)
End Function
Function capPreview(ByVal hCapWnd As Long, ByVal f As Boolean) As Boolean
capPreview = SendMessageAsLong(hCapWnd, WM_CAP_SET_PREVIEW, -(f), 0&)
End Function
Function capPreviewRate(ByVal hCapWnd As Long, ByVal wMS As Long) As Boolean
capPreviewRate = SendMessageAsLong(hCapWnd, WM_CAP_SET_PREVIEWRATE, wMS, 0&)
End Function