Hallo... Ich bin neu hier und erhoffe mir eine eventuelle Hilfe...
Ich habe mir zum erstellen eines Liveview das folgende Snippet aus dem Internet gesucht, um die Webcam in einer Picturebox anzuzeigen.
Das funktioniert auch wunderbar beim debuggen. Jedoch nur beim ersten debuggen. Möchte ich das Programm erneut aufrufen kommt nur ein Fenster, auf der ich die Videoquelle auswählen soll. Wenn ich das mache passiert aber nichts, und die Picturebox bleibt schwarz... Hat vielleicht jemand eine Idee?
Das Snippet ist folgendes:
Class ShowWebcam
Dim videoHandle As IntPtr
Declare Auto Function SendMessage Lib "user32" (ByVal hwnd As IntPtr, ByVal _
wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As _
Integer
Declare Auto Function capCreateCaptureWindow Lib "avicap32.dll" (ByVal _
lpszWindowName As String, ByVal dwStyle As Integer, ByVal x As Short, ByVal _
y As Integer, ByVal nWidth As Short, ByVal nHeight As Short, ByVal _
hWndParent As IntPtr, ByVal nID As Byte) As IntPtr
Const EM_LINEFROMCHAR As Integer = &HC9
Const EM_LINEINDEX As Integer = &HBB
Const WS_CHILD As Integer = &H40000000
Const WS_VISIBLE As Integer = &H10000000
Const WM_USER As Short = &H400S
Const WM_CAP_START As Short = &H400S
Const WM_CAP_EDIT_COPY As Short = WM_CAP_START + 30
Const WM_CAP_DRIVER_CONNECT As Short = WM_CAP_START + 10
Const WM_CAP_SET_PREVIEWRATE As Short = WM_CAP_START + 52
Const WM_CAP_SET_OVERLAY As Short = WM_CAP_START + 51
Const WM_CAP_SET_PREVIEW As Short = WM_CAP_START + 50
Const WM_CAP_DRIVER_DISCONNECT As Short = WM_CAP_START + 11
Function CreateCaptureWindow(ByRef hWndParent As IntPtr, Optional ByRef x _
As Short = 0, Optional ByRef y As Short = 0, Optional ByRef nWidth As _
Short = 640, Optional ByRef nHeight As Short = 420, Optional ByRef _
nCameraID As Integer = 0) As IntPtr
Dim previewHandle As IntPtr
previewHandle = capCreateCaptureWindow("Video", WS_CHILD + WS_VISIBLE, _
x, y, nWidth, nHeight, hWndParent, 1)
SendMessage(previewHandle, WM_CAP_DRIVER_CONNECT, nCameraID, 0)
SendMessage(previewHandle, WM_CAP_SET_PREVIEWRATE, 30, 0)
SendMessage(previewHandle, WM_CAP_SET_OVERLAY, 1, 0)
SendMessage(previewHandle, WM_CAP_SET_PREVIEW, 1, 0)
Return previewHandle
End Function
Sub Disconnect(ByRef nCaptureHandle As IntPtr, Optional ByRef nCameraID As _
Integer = 0)
SendMessage(nCaptureHandle, WM_CAP_DRIVER_DISCONNECT, nCameraID, 0)
End Sub
Sub Form1_FormClosing() Handles Me.FormClosing
Me.Disconnect(videoHandle)
End Sub
Sub Button1_Click() Handles Button1.Click
videoHandle = Me.CreateCaptureWindow(Picture1.Handle)
End Sub
End Class Das Fenster was kommt, wenn es nicht klappt ist folgendes:
Ich habe die Vermutung, dass die Webcam nach beenden des Programms nicht wieder freigegeben wird. Nach einem Neustart des PCs geht es wieder einmal...
Würde mich sehr über Hilfe freuen.
Mit freundlichen Grüßen
friloo
Beitrag wurde zuletzt am 16.02.14 um 00:32:35 editiert. |