Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit On
- Option Strict On
- Public Class Webcam
- Private Shared w32 As Win32Api
- Private Shared Shadows [Handle] As IntPtr
- Public Shared Sub Start()
- w32 = New Win32Api(Hauptform.PicBox.Handle, 352, 287)
- [Handle] = w32.GetCaptureHandle
- End Sub
- Public Shared Sub Beenden()
- w32.MyHandle = [Handle]
- If Not [Handle].Equals(IntPtr.Zero) Then
- w32.DisposeConnection()
- End If
- End Sub
- Public Shared Sub ManuellSnapshot()
- Dim Datum As String = My.Computer.Clock.LocalTime.Day & "." & My.Computer.Clock.LocalTime.Month & "." & My.Computer.Clock.LocalTime.Year
- Dim Uhrzeit As String = My.Computer.Clock.LocalTime.Hour & ";" & My.Computer.Clock.LocalTime.Minute & ";" & My.Computer.Clock.LocalTime.Second
- Dim Gesamt As String = Datum & Uhrzeit
- If Not [Handle].Equals(IntPtr.Zero) Then
- w32.MyHandle = [Handle]
- Dim img As Image = w32.GetImage()
- If img IsNot Nothing Then
- Hauptform.PicBox.Image = img
- End If
- End If
- IO.Directory.CreateDirectory("C:\Dokumente und Einstellungen\Chriz\Desktop\Buchhold Projekt\Snapshots\" & Date.Today & "\")
- Hauptform.PicBox.Image.Save("C:\Dokumente und Einstellungen\Chriz\Desktop\Buchhold Projekt\Snapshots\" & Date.Today & "\" & Uhrzeit & ".jpg")
- End Sub
- Public Shared Sub Snapshot()
- Dim Datum As String = My.Computer.Clock.LocalTime.Day & "." & My.Computer.Clock.LocalTime.Month & "." & My.Computer.Clock.LocalTime.Year
- Dim Uhrzeit As String = My.Computer.Clock.LocalTime.Hour & ";" & My.Computer.Clock.LocalTime.Minute & ";" & My.Computer.Clock.LocalTime.Second
- Dim Gesamt As String = Datum & Uhrzeit
- If Not [Handle].Equals(IntPtr.Zero) Then
- w32.MyHandle = [Handle]
- Dim img As Image = w32.GetImage()
- If img IsNot Nothing Then
- Hauptform.PicBox.Image = img
- End If
- End If
- IO.Directory.CreateDirectory("C:\Dokumente und Einstellungen\Chriz\Desktop\Buchhold Projekt\Fehlerlogs\" & Date.Today & "\")
- Hauptform.PicBox.Image.Save("C:\Dokumente und Einstellungen\Chriz\Desktop\Buchhold Projekt\Fehlerlogs\" & Date.Today & "\" & Uhrzeit & ".jpg")
- End Sub
- End Class
- 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)
- Private Const WM_CAP_EDIT_COPY As Integer = (WM_CAP_START + 30)
- #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 "Public"
- Public MyHandle As IntPtr
- #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 >= 320) And (Height >= 240) 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 ReadOnly Property GetImage() As Drawing.Image
- Get
- Return Me.SetCurrentImageToClipBoard()
- End Get
- End Property
- Private Function SetCurrentImageToClipBoard() As Drawing.Image
- Try
- My.Computer.Clipboard.Clear()
- SendMessage(Me.SetHandle(), Win32Api.WM_CAP_EDIT_COPY, 0, 0)
- Dim img As Image = My.Computer.Clipboard.GetImage
- If img IsNot Nothing Then
- Return img
- Else
- Return Nothing
- End If
- Catch
- Return Nothing
- End Try
- End Function
- Public Property SetHandle() As IntPtr
- Get
- Return MyHandle
- End Get
- Set(ByVal value As IntPtr)
- MyHandle = value
- End Set
- End Property
- Public Sub DisposeConnection()
- Dim result As Integer = SendMessage(Me.SetHandle(), Win32Api.WM_CAP_DRIVER_DISCONNECT, Win32Api.CameraId, 0)
- Debug.WriteLine("Disconnected: " & result.ToString())
- End Sub
- #End Region
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement