Postado Dom Fev 22, 2015 2:03 pm
Adicione:
1 PictureBox
2 Buttons
Renomeie:
Button 1 > Executar
Button 2 > Desconectar
Depois clique em project >> Adicionar windows Form >> Depois clique em ADD
1 PictureBox
2 Buttons
Renomeie:
Button 1 > Executar
Button 2 > Desconectar
Depois clique em project >> Adicionar windows Form >> Depois clique em ADD
De 2 cliques sobre o Form1 Abaixo de Public Class Form1 vocês adicione o seguinte codigo:
- Código:
Dim videoHandle As IntPtr
Dim an As Boolean = False
Declare Auto Function SendMessage Lib "user32" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
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
Const EM_LINEFROMCHAR As Integer = &HC9
Const EM_LINEINDEX As Integer = &HBB
Const WS_CHILD As Integer = &H40000000
Const WS_VISIBLE As Integer = &H10000000
Const WM_USER As Short = &H400S
Const WM_CAP_START As Short = &H400S
Const WM_CAP_EDIT_COPY As Short = WM_CAP_START + 30
Const WM_CAP_DRIVER_CONNECT As Short = WM_CAP_START + 10
Const WM_CAP_SET_PREVIEWRATE As Short = WM_CAP_START + 52
Const WM_CAP_SET_OVERLAY As Short = WM_CAP_START + 51
Const WM_CAP_SET_PREVIEW As Short = WM_CAP_START + 50
Const WM_CAP_DRIVER_DISCONNECT As Short = WM_CAP_START + 11
Logo Abaixo adicione o seguinte codigo:
- Código:
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
Dim previewHandle As IntPtr
previewHandle = capCreateCaptureWindow("Video", WS_CHILD + WS_VISIBLE, x, y, nWidth, nHeight, hWndParent, 1)
SendMessage(previewHandle, WM_CAP_DRIVER_CONNECT, nCameraID, 0)
SendMessage(previewHandle, WM_CAP_SET_PREVIEWRATE, 30, 0)
SendMessage(previewHandle, WM_CAP_SET_OVERLAY, 1, 0)
SendMessage(previewHandle, WM_CAP_SET_PREVIEW, 1, 0)
Return previewHandle
End Function
Sub Disconnect(ByRef nCaptureHandle As IntPtr, Optional ByRef nCameraID As Integer = 0)
SendMessage(nCaptureHandle, WM_CAP_DRIVER_DISCONNECT, nCameraID, 0)
End Sub
Sub Form2_FormClosing() Handles Me.FormClosing
Me.Disconnect(videoHandle)
End Sub
Depois de 2 cliques sobre o Button 1 e adicione o seguinte codigo:
- Código:
an = True
videoHandle = Me.CreateCaptureWindow(PictureBox1.Handle)
While an = True
Bild_Speichern()
End While
Depois de 2 cliques sobre o Button 2 e adicione o seguinte codigo:
- Código:
an = False
Me.Disconnect(videoHandle)
Depois por ultimo logo abaixo adicione o seguinte codigo:
- Código:
Private Sub Bild_Speichern()
Try
If (pictureBox1 IsNot Nothing) Then
Dim BildAlsDateiPfad As String = "C:\User\Desktop\Hallo"
Dim bm As Bitmap = pictureBox1.Image
bm.Save(BildAlsDateiPfad & ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
End If
Catch ex As Exception
MsgBox("Bild Wurde nicht gespeichert.", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub