Webcam in Picturebox

    • VB.NET

    Es gibt 1 Antwort in diesem Thema. Der letzte Beitrag () ist von Hacker-hack.

      Hallo VB`Ler, hier im Forum lese ich oft, dass Leute Probleme haben ihre Webcam in einer Picturebox anzeigen zu lassen.
      Ich habe nun mal ein kleines Tutorial erstellt.



      Zuerst erstellt ihr ein neues Projekt. Wichtig ist, dass die "Imports System.IO" importiert ist.
      Noch wichtig ist, dass dieser Code dann hier wie im bsp. im Formload ist.



      Quellcode

      1. Imports System.IO
      2. Public Class Form1
      3. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      4. 'Video starten'
      5. videoHandle = Me.CreateCaptureWindow(PictureBox1.Handle)
      6. 'video ende^^
      7. End Sub
      8. End Class



      Wenn ihr das gemacht habt, könnt ihr gemütlich den Code da unter platzieren.

      Quellcode

      1. Dim videoHandle As IntPtr
      2. Declare Auto Function SendMessage Lib "user32" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
      3. 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
      4. Const EM_LINEFROMCHAR As Integer = &HC9
      5. Const EM_LINEINDEX As Integer = &HBB
      6. Const WS_CHILD As Integer = &H40000000
      7. Const WS_VISIBLE As Integer = &H10000000
      8. ' Für die optimale Bildqualität müsst ihr hier ein wenig rumspielen mit den zahlen...
      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. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      33. Me.Close()
      34. End Sub




      Was ihr nun draus macht ist euch überlassen. Ihr könnt es in euer Spiel einbauen, oder in euere Überwachungssicherheitssoftware oder sonst was.
      Ich übernehme aber keine Haftung für schäden etc.




      Quellcode von :
      dotnet-snippets



      Edit by LaMa5:
      - Quelle verlinkt
      Dateien

      Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von „LaMa5“ ()

      Speichern von Videos Bilder usw.

      das ist gut hab mal probiert ohne Picturebox und dafür einen Button das hat auch funktioniert das bedeutet es geht eigentlich mit allem,
      aber ich habe mal das versucht und Form1 eingegeben und alles entfernt da hatte es nicht funktioniert.

      Eine Lösung habe ich selbst noch 5min basteln schon gefunden.

      Fügt einfach das hinzu.
      Entfernt aber Alles das unter Private Sub Form1_load... steht

      Private Sub CAM_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


      videoHandle = Me.CreateCaptureWindow(Me.Handle)
      End Sub


      Hab etwas gefunden das noch brauchbar ist sites.google.com/site/webcamli…ebcam-and-image-capturing
      Videos und Bilder ganz einfach speichern ähnlich wie bei der Software Gimp.

      Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Hacker-hack“ () aus folgendem Grund: Noch etwas Gefunden