CAPTURAR IMAGEM DA WEBCAM
Boa tarde Galera!!!!!!
Galera tô com o seguinte dilema.... fiz um cadastro em Visual Basic Net 2008 com banco de dados access.
Agora preciso capturar a imagem da webcam, na tela de cadastro do cliente.
Achei alguns exemplos na internet mas dá erro na execução, não exibe a imagem, usei até os links do macoratti, e não da certo.
alguém já fez ou tem um sistema assim.... pra poder me ajudar.... preciso de orientações ou de algum link de um exemplo que
realmente funcione no visual 2008. Detalhe o sistema operacional que estou usando é o Windows 8 32 bits
Abraço Galera
Galera tô com o seguinte dilema.... fiz um cadastro em Visual Basic Net 2008 com banco de dados access.
Agora preciso capturar a imagem da webcam, na tela de cadastro do cliente.
Achei alguns exemplos na internet mas dá erro na execução, não exibe a imagem, usei até os links do macoratti, e não da certo.
alguém já fez ou tem um sistema assim.... pra poder me ajudar.... preciso de orientações ou de algum link de um exemplo que
realmente funcione no visual 2008. Detalhe o sistema operacional que estou usando é o Windows 8 32 bits
Abraço Galera
NEGRON,
Já viu este registro?
====================================================
CAPTURA WEBCAM UTILIZANDO DIRECTSHOW
http://www.vbmania.com.br/index.php?modulo=detalhe&id=8947
====================================================
Outros exemplos:
====================================================
VB 2005 - Capturando imagens de uma WebCam
http://www.macoratti.net/07/08/vbn_wbc.htm
====================================================
VB .NET - Usando uma WebCam (de novo)
http://www.macoratti.net/11/12/vbn_cam1.htm
====================================================
How To Create Webcam Capture
https://code.msdn.microsoft.com/windowsapps/How-To-Create-Webcam-bbdcc90f
====================================================
Image: Capture an image from a Web cam
http://www.vb-tips.com/Webcam.aspx
====================================================
WebCam Fast Image Capture Service using WIA
http://www.codeproject.com/Articles/15219/WebCam-Fast-Image-Capture-Service-using-WIA
====================================================
[Vb.Net] WebCam Class (ICam)
http://www.vbforums.com/showthread.php?344471-Vb.Net-WebCam-Class-(ICam)
====================================================
[][ô]s,
Tunusat.
Já viu este registro?
====================================================
CAPTURA WEBCAM UTILIZANDO DIRECTSHOW
http://www.vbmania.com.br/index.php?modulo=detalhe&id=8947
====================================================
Outros exemplos:
====================================================
VB 2005 - Capturando imagens de uma WebCam
http://www.macoratti.net/07/08/vbn_wbc.htm
====================================================
VB .NET - Usando uma WebCam (de novo)
http://www.macoratti.net/11/12/vbn_cam1.htm
====================================================
How To Create Webcam Capture
https://code.msdn.microsoft.com/windowsapps/How-To-Create-Webcam-bbdcc90f
====================================================
Image: Capture an image from a Web cam
http://www.vb-tips.com/Webcam.aspx
====================================================
WebCam Fast Image Capture Service using WIA
http://www.codeproject.com/Articles/15219/WebCam-Fast-Image-Capture-Service-using-WIA
====================================================
[Vb.Net] WebCam Class (ICam)
http://www.vbforums.com/showthread.php?344471-Vb.Net-WebCam-Class-(ICam)
====================================================
[][ô]s,
Tunusat.
Tenta assim :
Imports System.Runtime.InteropServices
Imports System.Drawing.Drawing2D
Imports System
Public Class Form1
Const WM_CAP As Short = &H400S
Const WM_CAP_DRIVER_CONNECT As Integer = WM_CAP + 10
Const WM_CAP_DRIVER_DISCONNECT As Integer = WM_CAP + 11
Const WM_CAP_EDIT_COPY As Integer = WM_CAP + 30
Const WM_CAP_SET_PREVIEW As Integer = WM_CAP + 50
Const WM_CAP_SET_PREVIEWRATE As Integer = WM_CAP + 52
Const WM_CAP_SET_SCALE As Integer = WM_CAP + 53
Const WS_CHILD As Integer = &H40000000
Const WS_VISIBLE As Integer = &H10000000
Const SWP_NOMOVE As Short = &H2S
Const SWP_NOSIZE As Short = 1
Const SWP_NOZORDER As Short = &H4S
Const HWND_BOTTOM As Short = 1
Dim iDevice As Integer = 0
Dim hHwnd As Integer
Declare Function SendMessage Lib [Ô]user32[Ô] Alias [Ô]SendMessageA[Ô] (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, <MarshalAs(UnmanagedType.AsAny)> ByVal lParam As Object) As Integer
Declare Function SetWindowPos Lib [Ô]user32[Ô] Alias [Ô]SetWindowPos[Ô] (ByVal hwnd As Integer, ByVal hWndInsertAfter As Integer, ByVal x As Integer, ByVal y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer) As Integer
Declare Function DestroyWindow Lib [Ô]user32[Ô] (ByVal hndw As Integer) As Boolean
Declare Function capCreateCaptureWindowA 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 Short, ByVal hWndParent As Integer, ByVal nID As Integer) As Integer
Declare Function capGetDriverDescriptionA Lib [Ô]avicap32.dll[Ô] (ByVal wDriver As Short, ByVal lpszName As String, ByVal cbName As Integer, ByVal lpszVer As String, ByVal cbVer As Integer) As Boolean
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
carregaDispositivos()
If lstDispositivos.Items.Count > 0 Then
btnIniciar.Enabled = True
lstDispositivos.SelectedIndex = 0
btnIniciar.Enabled = True
Else
lstDispositivos.Items.Add([Ô]Não Tem dispositivo de captura instalado.[Ô])
btnIniciar.Enabled = False
End If
btnParar.Enabled = False
btnSalvar.Enabled = False
picCaptura.SizeMode = PictureBoxSizeMode.StretchImage
End Sub
Private Sub carregaDispositivos()
Dim strNome As String = Space(100)
Dim strVer As String = Space(100)
Dim bRetorna As Boolean
Dim x As Integer = 0
Do
bRetorna = capGetDriverDescriptionA(x, strNome, 100, strVer, 100)
If bRetorna Then lstDispositivos.Items.Add(strNome.Trim)
x += 1
Loop Until bRetorna = False
End Sub
Private Sub abreJanelaVisualizacao()
Dim iHeight As Integer = picCaptura.Height
Dim iWidth As Integer = picCaptura.Width
hHwnd = capCreateCaptureWindowA(iDevice, WS_VISIBLE Or WS_CHILD, 0, 0, 640, 480, picCaptura.Handle.ToInt32, 0)
If SendMessage(hHwnd, WM_CAP_DRIVER_CONNECT, iDevice, 0) Then
SendMessage(hHwnd, WM_CAP_SET_SCALE, True, 0)
SendMessage(hHwnd, WM_CAP_SET_PREVIEWRATE, 66, 0)
SendMessage(hHwnd, WM_CAP_SET_PREVIEW, True, 0)
SetWindowPos(hHwnd, HWND_BOTTOM, 0, 0, picCaptura.Width, picCaptura.Height, SWP_NOMOVE Or SWP_NOZORDER)
btnSalvar.Enabled = True
btnParar.Enabled = True
btnIniciar.Enabled = False
Else
DestroyWindow(hHwnd)
btnSalvar.Enabled = False
End If
End Sub
Private Sub fechaJanelaVisualizacao()
SendMessage(hHwnd, WM_CAP_DRIVER_DISCONNECT, iDevice, 0)
DestroyWindow(hHwnd)
End Sub
Private Sub btnIniciar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnIniciar.Click
iDevice = lstDispositivos.SelectedIndex
If iDevice <> -1 Then
abreJanelaVisualizacao()
Else
MsgBox([Ô]Selecione um dispositivo de video...[Ô])
End If
End Sub
Private Sub btnParar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnParar.Click
fechaJanelaVisualizacao()
btnSalvar.Enabled = False
btnIniciar.Enabled = True
btnParar.Enabled = False
End Sub
Private Sub btnSalvar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSalvar.Click
Dim dados As IDataObject
Dim bmap As Image
SendMessage(hHwnd, WM_CAP_EDIT_COPY, 0, 0)
dados = Clipboard.GetDataObject()
If dados.GetDataPresent(GetType(System.Drawing.Bitmap)) Then
bmap = CType(dados.GetData(GetType(System.Drawing.Bitmap)), Image)
picCaptura.Image = bmap
fechaJanelaVisualizacao()
btnSalvar.Enabled = False
btnParar.Enabled = False
btnIniciar.Enabled = True
If sfdImage.ShowDialog = System.Windows.Forms.DialogResult.OK Then
bmap.Save(sfdImage.FileName, Imaging.ImageFormat.Bmp)
End If
End If
End Sub
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If btnParar.Enabled Then
fechaJanelaVisualizacao()
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Application.Exit()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.picCaptura.ResetText()
End Sub
End Class
Imports System.Runtime.InteropServices
Imports System.Drawing.Drawing2D
Imports System
Public Class Form1
Const WM_CAP As Short = &H400S
Const WM_CAP_DRIVER_CONNECT As Integer = WM_CAP + 10
Const WM_CAP_DRIVER_DISCONNECT As Integer = WM_CAP + 11
Const WM_CAP_EDIT_COPY As Integer = WM_CAP + 30
Const WM_CAP_SET_PREVIEW As Integer = WM_CAP + 50
Const WM_CAP_SET_PREVIEWRATE As Integer = WM_CAP + 52
Const WM_CAP_SET_SCALE As Integer = WM_CAP + 53
Const WS_CHILD As Integer = &H40000000
Const WS_VISIBLE As Integer = &H10000000
Const SWP_NOMOVE As Short = &H2S
Const SWP_NOSIZE As Short = 1
Const SWP_NOZORDER As Short = &H4S
Const HWND_BOTTOM As Short = 1
Dim iDevice As Integer = 0
Dim hHwnd As Integer
Declare Function SendMessage Lib [Ô]user32[Ô] Alias [Ô]SendMessageA[Ô] (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, <MarshalAs(UnmanagedType.AsAny)> ByVal lParam As Object) As Integer
Declare Function SetWindowPos Lib [Ô]user32[Ô] Alias [Ô]SetWindowPos[Ô] (ByVal hwnd As Integer, ByVal hWndInsertAfter As Integer, ByVal x As Integer, ByVal y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer) As Integer
Declare Function DestroyWindow Lib [Ô]user32[Ô] (ByVal hndw As Integer) As Boolean
Declare Function capCreateCaptureWindowA 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 Short, ByVal hWndParent As Integer, ByVal nID As Integer) As Integer
Declare Function capGetDriverDescriptionA Lib [Ô]avicap32.dll[Ô] (ByVal wDriver As Short, ByVal lpszName As String, ByVal cbName As Integer, ByVal lpszVer As String, ByVal cbVer As Integer) As Boolean
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
carregaDispositivos()
If lstDispositivos.Items.Count > 0 Then
btnIniciar.Enabled = True
lstDispositivos.SelectedIndex = 0
btnIniciar.Enabled = True
Else
lstDispositivos.Items.Add([Ô]Não Tem dispositivo de captura instalado.[Ô])
btnIniciar.Enabled = False
End If
btnParar.Enabled = False
btnSalvar.Enabled = False
picCaptura.SizeMode = PictureBoxSizeMode.StretchImage
End Sub
Private Sub carregaDispositivos()
Dim strNome As String = Space(100)
Dim strVer As String = Space(100)
Dim bRetorna As Boolean
Dim x As Integer = 0
Do
bRetorna = capGetDriverDescriptionA(x, strNome, 100, strVer, 100)
If bRetorna Then lstDispositivos.Items.Add(strNome.Trim)
x += 1
Loop Until bRetorna = False
End Sub
Private Sub abreJanelaVisualizacao()
Dim iHeight As Integer = picCaptura.Height
Dim iWidth As Integer = picCaptura.Width
hHwnd = capCreateCaptureWindowA(iDevice, WS_VISIBLE Or WS_CHILD, 0, 0, 640, 480, picCaptura.Handle.ToInt32, 0)
If SendMessage(hHwnd, WM_CAP_DRIVER_CONNECT, iDevice, 0) Then
SendMessage(hHwnd, WM_CAP_SET_SCALE, True, 0)
SendMessage(hHwnd, WM_CAP_SET_PREVIEWRATE, 66, 0)
SendMessage(hHwnd, WM_CAP_SET_PREVIEW, True, 0)
SetWindowPos(hHwnd, HWND_BOTTOM, 0, 0, picCaptura.Width, picCaptura.Height, SWP_NOMOVE Or SWP_NOZORDER)
btnSalvar.Enabled = True
btnParar.Enabled = True
btnIniciar.Enabled = False
Else
DestroyWindow(hHwnd)
btnSalvar.Enabled = False
End If
End Sub
Private Sub fechaJanelaVisualizacao()
SendMessage(hHwnd, WM_CAP_DRIVER_DISCONNECT, iDevice, 0)
DestroyWindow(hHwnd)
End Sub
Private Sub btnIniciar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnIniciar.Click
iDevice = lstDispositivos.SelectedIndex
If iDevice <> -1 Then
abreJanelaVisualizacao()
Else
MsgBox([Ô]Selecione um dispositivo de video...[Ô])
End If
End Sub
Private Sub btnParar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnParar.Click
fechaJanelaVisualizacao()
btnSalvar.Enabled = False
btnIniciar.Enabled = True
btnParar.Enabled = False
End Sub
Private Sub btnSalvar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSalvar.Click
Dim dados As IDataObject
Dim bmap As Image
SendMessage(hHwnd, WM_CAP_EDIT_COPY, 0, 0)
dados = Clipboard.GetDataObject()
If dados.GetDataPresent(GetType(System.Drawing.Bitmap)) Then
bmap = CType(dados.GetData(GetType(System.Drawing.Bitmap)), Image)
picCaptura.Image = bmap
fechaJanelaVisualizacao()
btnSalvar.Enabled = False
btnParar.Enabled = False
btnIniciar.Enabled = True
If sfdImage.ShowDialog = System.Windows.Forms.DialogResult.OK Then
bmap.Save(sfdImage.FileName, Imaging.ImageFormat.Bmp)
End If
End If
End Sub
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If btnParar.Enabled Then
fechaJanelaVisualizacao()
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Application.Exit()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.picCaptura.ResetText()
End Sub
End Class
Cara eu comprei uma OCX que faz capturas de imagens e vÃdeos, um pouco salgadinha, mas só comprei por uma exigencia devido a ser uma aplicação de captura de imagens para exames médicos. Mas vc já pensou em apenas colocar um botão de carregar uma imagem ao invés de fazer esse trabalho todo?
Cara
Desenvolvi uma dll que faz a captura de imagens de webcam, câmeras fotográficas e scanner... independente do modelo do equipamento
Se estiver interessado, me passa teu email que te envio uma cópia da dll ou até mesmo o código fonte se preferir
Desenvolvi uma dll que faz a captura de imagens de webcam, câmeras fotográficas e scanner... independente do modelo do equipamento
Se estiver interessado, me passa teu email que te envio uma cópia da dll ou até mesmo o código fonte se preferir
Tópico encerrado , respostas não são mais permitidas