Form als Bild speichern

  • VB.NET

Es gibt 7 Antworten in diesem Thema. Der letzte Beitrag () ist von Marceliboy.

    Genauere Info

    ich möchte meine Form, mit einer PictureBox, die meine Webcam anzeigt als *.jpg speichern
    Bisheriger Code der die Webcam anzeigt:

    VB.NET-Quellcode

    1. Public Class Form1
    2. Public videoHandle As IntPtr
    3. Private 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. Const EM_LINEFROMCHAR As Integer = &HC9
    5. Const EM_LINEINDEX As Integer = &HBB
    6. Private Declare Auto Function capCreateCaptureWindow 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 Integer, ByVal hWndParent As IntPtr, ByVal nID As Integer) As IntPtr
    7. Private Const WS_CHILD As Integer = &H40000000
    8. Private Const WS_VISIBLE As Integer = &H10000000
    9. Private Const WM_USER As Short = &H400S
    10. Private Const WM_CAP_START As Short = &H400S
    11. Private Const WM_CAP_EDIT_COPY As Integer = (WM_CAP_START + 30)
    12. Private Const WM_CAP_DRIVER_CONNECT As Integer = (WM_CAP_START + 10)
    13. Private Const WM_CAP_SET_PREVIEWRATE As Integer = (WM_CAP_START + 52)
    14. Private Const WM_CAP_SET_OVERLAY As Integer = (WM_CAP_START + 51)
    15. Private Const WM_CAP_SET_PREVIEW As Integer = (WM_CAP_START + 50)
    16. Private Const WM_CAP_DRIVER_DISCONNECT As Integer = (WM_CAP_START + 11)
    17. Public Function CreateCaptureWindow(ByRef hWndParent As IntPtr, Optional ByRef x As Integer = 0, Optional ByRef y As Integer = 0, Optional ByRef nWidth As Integer = 320, Optional ByRef nHeight As Integer = 240, 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. Public Function CapturePicture(ByRef nCaptureHandle As IntPtr) As System.Drawing.Image
    27. My.Computer.Clipboard.Clear()
    28. SendMessage(nCaptureHandle, WM_CAP_EDIT_COPY, 0, 0)
    29. Return My.Computer.Clipboard.GetImage
    30. End Function
    31. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    32. videoHandle = Me.CreateCaptureWindow(Me.PictureBox1.Handle)
    33. Dim Picture As System.Drawing.Image
    34. Picture = CapturePicture(videoHandle)
    35. Picture.Save(My.Computer.FileSystem.SpecialDirectories.Desktop + "\" + "pic.bmp")
    36. End Sub
    37. End Class
    Wenn Overlay genutzt wird, sollte der Screenshot nur ein einfarbiges Bild bringen. Also Overlay aus, AutoRedraw der Picturebox aus und dessen Grafik dann speichern. So habe ich damals Bilder für ein LCD digitalisiert. Allerdings progge ich nur in VB6 für den PC.
    Gruß
    Peterfido

    Keine Unterstützung per PN!