Moin Moin

ich habe mir einen code besorfgt um meine webcam mit vb.net abzufragen .
Das klappt auch wunderbar(api32.dll)

nun möchte ich Per click bilder davon abspeichern und farben erkennen oder
Pixel auslesen.
Ich habe gegoogelt und gesucht.
Ich bekomme es nicht hin. her der VB.net code




Option Explicit On
Option Strict On

Public Class Form1
Dim wort As String
Private w32 As Win32Api
Private Shadows [Handle] As IntPtr
Dim Bild As Bitmap
Dim number2str As String
Dim number As Integer
Dim x As Integer
Dim y As Integer






Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click
w32 = New Win32Api(Me.picturebox1.Handle, 704, 574)
[Handle] = w32.GetCaptureHandle
Me.Button1.Enabled = False


End Sub

Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) _
Handles Me.FormClosing
If Not [Handle].Equals(IntPtr.Zero) Then
w32.DisposeConnection([Handle])
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button2.Click
If Not [Handle].Equals(IntPtr.Zero) Then
w32.DisposeConnection([Handle])
Me.Button1.Enabled = True
End If
End Sub

Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles picturebox1.Click



End Sub


Public Class Win32Api

#Region "Api Functions"

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 hWnd As IntPtr, _
ByVal nID As Integer) _
As IntPtr


Private Declare Auto Function SendMessage Lib "user32.dll" ( _
ByVal hwnd As IntPtr, _
ByVal uMsg As Integer, _
ByVal wParam As Integer, _
ByVal lParam As Integer) _
As Integer

#End Region

#Region "Constants"

Private Const WM_USER As Int32 = &H400
Private Const WS_CHILD As Integer = &H40000000
Private Const WS_VISIBLE As Integer = &H10000000
Private Const WM_CAP_START As Integer = WM_USER
Private Const WM_CAP_DRIVER_CONNECT As Integer = (WM_CAP_START + 10)
Private Const WM_CAP_SET_PREVIEWRATE As Integer = (WM_CAP_START + 52)
Private Const WM_CAP_SET_OVERLAY As Integer = (WM_CAP_START + 51)
Private Const WM_CAP_SET_PREVIEW As Integer = (WM_CAP_START + 50)
Private Const WM_CAP_DRIVER_DISCONNECT As Integer = (WM_CAP_START + 11)

#End Region

#Region "Private"

Private _hwnd As IntPtr
Private _width As Integer
Private _height As Integer

#End Region

#Region "Camera Id"

Private Const CameraId As Integer = 0

#End Region

#Region "Frames"

Private Const Frames As Integer = 24

#End Region

#Region "Positions"

Private x As Integer = 0
Private y As Integer = 0

#End Region

#Region "Constructor"

Public Sub New(ByVal hWnd As IntPtr, ByVal Width As Integer, ByVal Height As Integer)
If Not hWnd.Equals(IntPtr.Zero) Then
Me._hwnd = hWnd
If (Width >= 640) And (Height >= 480) Then
Me._width = Width : Me._height = Height
Else
Return
End If
Else
Return
End If
End Sub

#End Region

#Region "Functions"

Public Function GetCaptureHandle() As IntPtr
Dim [Handle] As IntPtr = Win32Api.capCreateCaptureWindow("CaptureWindow", _
Win32Api.WS_CHILD + Win32Api.WS_VISIBLE, _
x, y, _
Me._width, Me._height, _
Me._hwnd, _
Win32Api.CameraId)
SendMessage([Handle], Win32Api.WM_CAP_DRIVER_CONNECT, Win32Api.CameraId, 0)
SendMessage([Handle], Win32Api.WM_CAP_SET_PREVIEWRATE, Win32Api.Frames, 0)
SendMessage([Handle], Win32Api.WM_CAP_SET_OVERLAY, 1, 0)
SendMessage([Handle], Win32Api.WM_CAP_SET_PREVIEW, 1, 0)
If Not [Handle].Equals(IntPtr.Zero) Then
Return [Handle]
Else
Return IntPtr.Zero
End If
End Function

Public Sub DisposeConnection(ByVal [Handle] As IntPtr)
Dim result As Integer = SendMessage([Handle], Win32Api.WM_CAP_DRIVER_DISCONNECT, Win32Api.CameraId, 0)
Debug.WriteLine("Disconnected: " & result.ToString())
End Sub

#End Region

End Class





Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click


End Sub


End Class


vieleicht kann mir jemand helfen

danke
Micha