Ma pictureBox (webcam intégrée)reste Noire

huberic80 Messages postés 4 Date d'inscription vendredi 17 avril 2009 Statut Membre Dernière intervention 26 mai 2016 - 25 mai 2016 à 19:17
huberic80 Messages postés 4 Date d'inscription vendredi 17 avril 2009 Statut Membre Dernière intervention 26 mai 2016 - 26 mai 2016 à 10:54
Bonjour,
Je développe une application utilisant ma webcam intégrée, je me connecte bien à la webcam, mais le soucis c'est que ma picturebox reste noire.
Elle apparait bien dans ma listebox(Microsoft WMD ImageCapture(Win32)) et le voyant s'allume bien mais pas moyen d'avoir autre chose qu'une picturebox noire.
Pouvez-vous m'aider svp???



--

7 réponses

ucfoutu Messages postés 18038 Date d'inscription lundi 7 décembre 2009 Statut Modérateur Dernière intervention 11 avril 2018 211
25 mai 2016 à 20:39
Bonjour,
- Avec quel outil de développement ? (tu as ouvert cette discussion dans le forum général Visual Basic) ?
- Avec quel code ?
0
huberic80 Messages postés 4 Date d'inscription vendredi 17 avril 2009 Statut Membre Dernière intervention 26 mai 2016
25 mai 2016 à 20:54
Bjr ucfoutu,

Je développe avec Microsoft Visual Basic 2010 Express,

Voici mon code :
-------------------------------------------------------------------------
Option Explicit On
Option Strict Off

Imports System
Imports System.Runtime
Imports System.Runtime.InteropServices
Public Class Form1

'Déclarations rales
Public Const WM_CAP As Short = &H400S

Public Const WM_CAP_DRIVER_CONNECT As Integer = WM_CAP + 10
Public Const WM_CAP_DRIVER_DISCONNECT As Integer = WM_CAP + 11
Public Const WM_CAP_EDIT_COPY As Integer = WM_CAP + 30

Public Const WM_CAP_SET_PREVIEW As Integer = WM_CAP + 50
Public Const WM_CAP_SET_PREVIEWRATE As Integer = WM_CAP + 52
Public Const WM_CAP_SET_SCALE As Integer = WM_CAP + 53
Public Const WS_CHILD As Integer = &H40000000
Public Const WS_VISIBLE As Integer = &H10000000
Public Const SWP_NOMOVE As Short = &H2S
Public Const SWP_NOSIZE As Short = 1
Public Const SWP_NOZORDER As Short = &H4S
Public Const HWND_BOTTOM As Short = 1

Public iDevice As Integer = 0 ' Current device ID
Public hHwnd As Integer ' Handle to preview window

Public 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

Public 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

Public Declare Function DestroyWindow Lib "user32" (ByVal hndw As Integer) As Boolean

Public 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

Public 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 Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Label1.Text = Format(Now, "hh:mm:ss")
End Sub


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ValidH.Click
Label2.Text = ComboBox1.Text + ":" + ComboBox2.Text + ":00"

End Sub

Private Sub Label1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.TextChanged
If (Label1.Text.Equals(Label2.Text)) = True Then
Label3.Text = "CAPTURE ACTIVATEE"
OpenPreviewWindow()
End If
End Sub
'Initialize Webcam Device
'This function is used to list all installed Webcam Device
Private Sub LoadDeviceList()
On Error Resume Next
Dim strName As String = Space(100)
Dim strVer As String = Space(100)
Dim bReturn As Boolean
Dim x As Integer = 0

Do
bReturn = capGetDriverDescriptionA(x, strName, 100, strVer, 100)
If bReturn Then lst1.Items.Add(strName.Trim)
x += 1
Application.DoEvents()
Loop Until bReturn = False

End Sub
'Start Device Capture
'This function is used to start capture frame.
'Open View
Private Sub OpenPreviewWindow()
On Error Resume Next

Dim iHeight As Integer = pview.Height

Dim iWidth As Integer = pview.Width

'
' Open Preview window in picturebox
'
hHwnd = capCreateCaptureWindowA(iDevice, WS_VISIBLE Or WS_CHILD, 0, 0, 640, _
480, pview.Handle.ToInt32, 0)

'
' Connect to device
'
If SendMessage(hHwnd, WM_CAP_DRIVER_CONNECT, iDevice, 0) Then
'
'Set the preview scale
'
SendMessage(hHwnd, WM_CAP_SET_SCALE, True, 0)

'
'Set the preview rate in milliseconds
'
SendMessage(hHwnd, WM_CAP_SET_PREVIEWRATE, 66, 0)
'
'Start previewing the image from the camera
'
SendMessage(hHwnd, WM_CAP_SET_PREVIEW, True, 0)
'
' Resize window to fit in picturebox
'
SetWindowPos(hHwnd, HWND_BOTTOM, 0, 0, pview.Width, pview.Height, _
SWP_NOMOVE Or SWP_NOZORDER)

Else
'
' Error connecting to device close window
'
DestroyWindow(hHwnd)

End If
End Sub
'Stop Device Capture
'This function is used to close Capture Function.
Private Sub ClosePreviewWindow()
On Error Resume Next
'
' Disconnect from device
'
SendMessage(hHwnd, WM_CAP_DRIVER_DISCONNECT, iDevice, 0)

'
' close window
'
DestroyWindow(hHwnd)
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Enabled = True
LoadDeviceList()
End Sub

Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click
Dim data As IDataObject
Dim bmap As Image


SendMessage(hHwnd, WM_CAP_EDIT_COPY, 0, 0)
data = Clipboard.GetDataObject()
If data.GetDataPresent(GetType(System.Drawing.Bitmap)) Then
bmap = CType(data.GetData(GetType(System.Drawing.Bitmap)), Image)
pview.Image = bmap

If sfdImage.ShowDialog = Windows.Forms.DialogResult.OK Then
bmap.Save(sfdImage.FileName, Imaging.ImageFormat.Bmp)
End If
End If
End Sub

Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
ClosePreviewWindow()
btnStart.Enabled = True
btnStop.Enabled = False

End Sub

Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
OpenPreviewWindow()
btnStart.Enabled = False
btnStop.Enabled = True
End Sub


End Class

Merci d'avance
0
huberic80 Messages postés 4 Date d'inscription vendredi 17 avril 2009 Statut Membre Dernière intervention 26 mai 2016
25 mai 2016 à 20:55
info je travail sur un portable Lenovo et Windows 8.1
0
ucfoutu Messages postés 18038 Date d'inscription lundi 7 décembre 2009 Statut Modérateur Dernière intervention 11 avril 2018 211
25 mai 2016 à 20:57
1) Discussion donc déplacée vers le sous-forum (VB.Net) où il fallait l'ouvrir.
2) je ne suis pas VB.Nettiste. Il te faudra donc attendre qu'un développeur VB.Net passe par là.

0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
ucfoutu Messages postés 18038 Date d'inscription lundi 7 décembre 2009 Statut Modérateur Dernière intervention 11 avril 2018 211
26 mai 2016 à 07:43
Je vois que ta discussion n'intéresse pas vraiment.
- Il est vrai que, n'ayant pas pris non plus la peine de présenter ton code entre balises code, il est pénible à suivre...
- tu devrais, je pense, t'intéresser à l'utilisation de la librairie avicap (avicap.dll).
0
ucfoutu Messages postés 18038 Date d'inscription lundi 7 décembre 2009 Statut Modérateur Dernière intervention 11 avril 2018 211
26 mai 2016 à 08:10
Tiens
Voilà un exemple d'utilisation de cette librairie.
Il est en VB6, mais son adaptation pour VB.Net devrait être simple.
http://codes-sources.commentcamarche.net/source/30202-enregistrer-un-video-d-une-webcam

0
huberic80 Messages postés 4 Date d'inscription vendredi 17 avril 2009 Statut Membre Dernière intervention 26 mai 2016
26 mai 2016 à 10:54
ok merci ucfoutu de ta promptitet de ton serieux
0
Rejoignez-nous