WEBCAN VB.NET 2015

DION899 24/04/2017 17:30:01
#473517
Boa tarde pessoal, estou com um problema que não sei resolver, estou tentando fazer uma tela de captura de foto pela webcan, no vb2005 funcionava bem mais no vb2015 não esta funcionando.
segue o codigo que utilizo.

Imports System.Runtime.InteropServices

[ô]constantes usadas na DLL
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 carregaDispositivos()
Dim strNome As String = Space(100)
Dim strVer As String = Space(100)
Dim bRetorna As Boolean
Dim x As Integer = 0

[ô]
[ô] Carrega os dispositivos em lstDevices
Do
[ô]
[ô] Obtem o nome e a versão Driver
bRetorna = capGetDriverDescriptionA(x, strNome, 100, strVer, 100)

[ô]
[ô] se existir um dispositivo inclui o nome da lista
[ô]If bRetorna Then lstDispositivos.Items.Add(strNome.Trim)
x += 1
Loop Until bRetorna = False
End Sub

Private Sub abreJanelaVisualizacao()
Dim iHeight As Integer = ImgCamera.Height
Dim iWidth As Integer = ImgCamera.Width

[ô] Abre a janela de visualização no picturebox
hHwnd = capCreateCaptureWindowA(iDevice, WS_VISIBLE Or WS_CHILD, 0, 0, 640,
480, ImgCamera.Handle.ToInt32, 0)

[ô] Conecta com o drive
If SendMessage(hHwnd, WM_CAP_DRIVER_CONNECT, iDevice, 0) Then

[ô]Define a escala de previsão
SendMessage(hHwnd, WM_CAP_SET_SCALE, True, 0)

[ô]Define a taxa de visualização em milisegundos
SendMessage(hHwnd, WM_CAP_SET_PREVIEWRATE, 66, 0)

[ô]Iniciar a visualização da imagem a partir da camara
SendMessage(hHwnd, WM_CAP_SET_PREVIEW, True, 0)

[ô] Redimensiona a janela para se ajustar no picturebox
SetWindowPos(hHwnd, HWND_BOTTOM, 0, 0, ImgCamera.Width, ImgCamera.Height,
SWP_NOMOVE Or SWP_NOZORDER)
Else
[ô] Erro de conexão fecha a janela de dispostivos
DestroyWindow(hHwnd)
End If
End Sub

Private Sub fechaJanelaVisualizacao()
[ô] Desconecta do dispositivo
SendMessage(hHwnd, WM_CAP_DRIVER_DISCONNECT, iDevice, 0)

[ô] fecha a chama a janela
DestroyWindow(hHwnd)
End Sub

Private Sub FrmDAlunos_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ImgCamera.SizeMode = PictureBoxSizeMode.StretchImage
End Sub

[ô]botão para estarta a webcan.
Private Sub btwebstart_Click(sender As Object, e As EventArgs) Handles btwebstart.Click
abreJanelaVisualizacao()
End Sub
KERPLUNK 24/04/2017 17:44:27
#473518
Primeiramante: webcaM e [Ô]mas[Ô] não [Ô]mais[Ô]. Segundo, você chegou a fazer um debug?
DION899 24/04/2017 19:26:10
#473526
Sim não da erro no debug, quando clico no botão start o picturebox fica preto, não funciona, já testei a webcam do meu note, esta funcionando normalmente no aplicativo de webcam do note.
KERPLUNK 24/04/2017 19:42:38
#473532
As chamadas API que estou vendo, dependem de uma DLL chamada avicap32.dll. Ela está presente no computador que você está querendo rodar?
MESTRE 25/04/2017 07:36:15
#473542
Amigo, uso o AForge e recomendo existem várias sources e exemplos espalhados por aí, nunca tive nenhum problema..
ele funciona tanto com webcam de notebook , usb etc etc.

http://www.aforgenet.com/framework/samples/video.html
https://code.google.com/archive/p/aforge/
DION899 27/04/2017 13:19:18
#473622
MESTRE vou dá uma olhada.
Faça seu login para responder