Usare WebCam in Visual Basic
Inviato: lun dic 23, 2013 8:04 pm
Il forum italiano su PC, Internet e smartphone
https://turbolab.it/forum/
ho copiato queste righe di codice in questo modo:Andy94 ha scritto:Nel link a seguire trovi delle indicazioni interessanti per fare ciò che ti serve.
http://www.dotnethell.it/articles/WebcamCapture.aspx
Premetto che non ho mai provato, ma è sicuramente interessante un tuo feedback a riguardo.
Codice: Seleziona tutto
Public Class Form1
Public Declare Function capGetDriverDescriptionA Lib "avicap32.dll" (ByVal wDriver As Short, ByVal lpszName As String, ByVal cbName As Integer, ByVal lpszVer As String, ByVal cbVer As Integer) As Boolean
Public Declare Function capCreateCaptureWindowA Lib "avicap32.dll" _
(ByVal lpszWindowName As String, ByVal dwStyle As Integer, _
ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, _
ByVal nHeight As Short, ByVal hWndParent As Integer, _
ByVal nID As Integer) As Integer
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, _
ByVal lParam As Object) As Integer
Public Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" (ByVal hwnd As Integer, _
ByVal hWndInsertAfter As Integer, ByVal x As Integer, ByVal y As Integer, _
ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer) As Integer
'Handle della finestra di preview
Dim hHwnd As Integer
'Dico alla dll di dirigere il flusso alla mia finestra di preview
hHwnd = capCreateCaptureWindowA(iDevice, WS_VISIBLE Or WS_CHILD, 0, 0, 640, _
480, objPreview.Handle.ToInt32, 0)
SendMessage(hHwnd, WM_CAP_DRIVER_CONNECT, iDevice, 0)
'Imposto la preview
SendMessage(hHwnd, WM_CAP_SET_SCALE, True, 0)
'imposto il rate in millisecondi
SendMessage(hHwnd, WM_CAP_SET_PREVIEWRATE, 66, 0)
'Faccio partire la preview
SendMessage(hHwnd, WM_CAP_SET_PREVIEW, True, 0)
'Scalo la preview all'interno della dimensione del mio box immagine
SetWindowPos(hHwnd, HWND_BOTTOM, 0, 0, iWidth, iHeight, SWP_NOMOVE Or SWP_NOZORDER)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim strName As String = Space(100)
Dim strVer As String = Space(100)
Dim bReturn As Boolean
Dim x As Integer = 0
'carica la lista completa nell'elenco
Do
'ricava il nome del driver e la versione
bReturn = capGetDriverDescriptionA(x, strName, 100, strVer, 100)
'se un device lo aggiunge alla lista
If bReturn Then lstDevices.Items.Add(strName.Trim)
x += 1
Loop Until bReturn = False
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
End Sub
End Class