Merkwürdiges Webcam Problem

  • VB.NET

Es gibt 2 Antworten in diesem Thema. Der letzte Beitrag () ist von dr. Nick.

    Merkwürdiges Webcam Problem

    Hallo!

    Ich versuche gerade eine Webcam in vb.net zum laufen zu bringen, 1 PictureBox, 1 Button und dieser Code:

    VB.NET-Quellcode

    1. Class ShowWebcam
    2. Dim videoHandle As IntPtr
    3. Declare Auto Function SendMessage Lib "user32" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
    4. 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
    5. Const EM_LINEFROMCHAR As Integer = &HC9
    6. Const EM_LINEINDEX As Integer = &HBB
    7. Const WS_CHILD As Integer = &H40000000
    8. Const WS_VISIBLE As Integer = &H10000000
    9. Const WM_USER As Short = &H400S
    10. Const WM_CAP_START As Short = &H400S
    11. Const WM_CAP_EDIT_COPY As Short = WM_CAP_START + 30
    12. Const WM_CAP_DRIVER_CONNECT As Short = WM_CAP_START + 10
    13. Const WM_CAP_SET_PREVIEWRATE As Short = WM_CAP_START + 52
    14. Const WM_CAP_SET_OVERLAY As Short = WM_CAP_START + 51
    15. Const WM_CAP_SET_PREVIEW As Short = WM_CAP_START + 50
    16. Const WM_CAP_DRIVER_DISCONNECT As Short = WM_CAP_START + 11
    17. 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
    18. Dim previewHandle As IntPtr
    19. previewHandle = capCreateCaptureWindow("Video", WS_CHILD + WS_VISIBLE, x, y, nWidth, nHeight, hWndParent, 1)
    20. SendMessage(previewHandle, WM_CAP_DRIVER_CONNECT, nCameraID, 0)
    21. SendMessage(previewHandle, WM_CAP_SET_PREVIEWRATE, 30, 0)
    22. SendMessage(previewHandle, WM_CAP_SET_OVERLAY, 1, 0)
    23. SendMessage(previewHandle, WM_CAP_SET_PREVIEW, 1, 0)
    24. Return previewHandle
    25. End Function
    26. Sub Disconnect(ByRef nCaptureHandle As IntPtr, Optional ByRef nCameraID As Integer = 0)
    27. SendMessage(nCaptureHandle, WM_CAP_DRIVER_DISCONNECT, nCameraID, 0)
    28. End Sub
    29. Sub Form1_FormClosing() Handles Me.FormClosing
    30. Me.Disconnect(videoHandle)
    31. End Sub
    32. Sub Button1_Click() Handles Button1.Click
    33. videoHandle = Me.CreateCaptureWindow(PictureBox1.Handle)
    34. End Sub
    35. End Class



    So das ganze Problem ist jetzt, es funktioniert genau 1 mal. Sobald ich das Fenster schließe und öffne klappt es nicht mehr. Wenn ich jetzt den PC Neu Starte. Klappt es wieder, 1 mal.

    Witzigerweise beim 1. mal klicke ich auf Button1 und es läuft los

    Beim 2. mal klicke ich auf Button1 dann kommt das Videoquellen auswahlfenster -> Übernehmen, OK und dann bleibt das Fenster schwarz


    PC Daten:
    Intel Core i5
    NVidia GeForce GT610
    Windows 10 x64


    ich hoffe es kann mir jemand helfen

    *Topic verschoben, Code-BBCode korrigiert*

    Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von „Marcus Gräfe“ ()

    Leider kann ich dir nicht helfen, da ich keine Webcam besitze. Dennoch bin ich auf folgende Library gestoßen welche den Umgang mit Webcams vereinfachen soll:
    easywebcam.codeplex.com/
    Mfg: Gather
    Private Nachrichten bezüglich VB-Fragen werden Ignoriert!