IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB.NET Discussion :

Photo avec webcam sous Windows 8 - Non-RT [Débutant]


Sujet :

VB.NET

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Homme Profil pro
    Inscrit en
    Janvier 2013
    Messages
    15
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations forums :
    Inscription : Janvier 2013
    Messages : 15
    Par défaut Photo avec webcam sous Windows 8 - Non-RT
    Bonjour à tous !
    Comme d'habitude,j'ai une question bien chi**** qui m'occupe pas mal ces derniers temps:
    Comment peut-on prendre une photo avec une webcam de PC portable qui tourne sous Win 8?
    J'ai essayé avec WIA mais il ne reconnais pas ma cam de PC, juste celles de mon téléphone.
    J'ai trouvé ça sur le net:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
            Dim returnImg As Image = Nothing
            Dim DefaultDevice As WIA.Device
            Dim Dialog1 As New WIA.CommonDialog
            DefaultDevice = Dialog1.ShowSelectDevice
    Est-ce que quelqu'un à une idée de la marche à suivre?
    Je dois passer par une autre API?
    Merci d'avance à tous !!!

    [EDIT] Je compte developper une appli de controle adossée à une BDD ou les photos serviront de "preuve". Idéalement l'appli tournera sur une tablette Win8 pro.

  2. #2
    Membre averti
    Homme Profil pro
    Inscrit en
    Janvier 2013
    Messages
    15
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations forums :
    Inscription : Janvier 2013
    Messages : 15
    Par défaut Trouvé !!
    J'ai trouvé ça sur le net, et ça marche bien mais en 640x480...
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    Imports System.Runtime.InteropServices
     
    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 ' Current device ID
        Dim hHwnd As Integer ' Handle to preview window
     
        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
            LoadDeviceList()
            If lstDevices.Items.Count > 0 Then
                btnStart.Enabled = True
                lstDevices.SelectedIndex = 0
                btnStart.Enabled = True
            Else
                lstDevices.Items.Add("No Capture Device")
                btnStart.Enabled = False
            End If
     
            btnStop.Enabled = False
            btnSave.Enabled = False
            picCapture.SizeMode = PictureBoxSizeMode.StretchImage
        End Sub
     
        Private Sub LoadDeviceList()
            Dim strName As String = Space(100)
            Dim strVer As String = Space(100)
            Dim bReturn As Boolean
            Dim x As Integer = 0
     
            ' 
            ' Load name of all avialable devices into the lstDevices
            '
     
            Do
                '
                '   Get Driver name and version
                '
                bReturn = capGetDriverDescriptionA(x, strName, 100, strVer, 100)
     
                '
                ' If there was a device add device name to the list
                '
                If bReturn Then lstDevices.Items.Add(strName.Trim)
                x += 1
            Loop Until bReturn = False
        End Sub
     
        Private Sub OpenPreviewWindow()
            Dim iHeight As Integer = picCapture.Height
            Dim iWidth As Integer = picCapture.Width
     
            '
            ' Open Preview window in picturebox
            '
            hHwnd = capCreateCaptureWindowA(iDevice, WS_VISIBLE Or WS_CHILD, 0, 0, 640, _
                480, picCapture.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, picCapture.Width, picCapture.Height, _
                        SWP_NOMOVE Or SWP_NOZORDER)
     
                btnSave.Enabled = True
                btnStop.Enabled = True
                btnStart.Enabled = False
            Else
                '
                ' Error connecting to device close window
                ' 
                DestroyWindow(hHwnd)
     
                btnSave.Enabled = False
            End If
        End Sub
     
        Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
            iDevice = lstDevices.SelectedIndex
            OpenPreviewWindow()
        End Sub
     
        Private Sub ClosePreviewWindow()
            '
            ' Disconnect from device
            '
            SendMessage(hHwnd, WM_CAP_DRIVER_DISCONNECT, iDevice, 0)
     
            '
            ' close window
            '
     
            DestroyWindow(hHwnd)
        End Sub
     
        Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
            ClosePreviewWindow()
            btnSave.Enabled = False
            btnStart.Enabled = True
            btnStop.Enabled = False
        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
     
            '
            ' Copy image to clipboard
            '
            SendMessage(hHwnd, WM_CAP_EDIT_COPY, 0, 0)
     
            '
            ' Get image from clipboard and convert it to a bitmap
            '
            data = Clipboard.GetDataObject()
            If data.GetDataPresent(GetType(System.Drawing.Bitmap)) Then
                bmap = CType(data.GetData(GetType(System.Drawing.Bitmap)), Image)
                picCapture.Image = bmap
                ClosePreviewWindow()
                btnSave.Enabled = False
                btnStop.Enabled = False
                btnStart.Enabled = True
     
                If sfdImage.ShowDialog = 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 btnStop.Enabled Then
                ClosePreviewWindow()
            End If
        End Sub
    End Class
    Quelqu'un pourrais m'expliquer comment augmenter la résolution pour exploiter ma caméra au maximum de sa résolution?
    Merci d'avance !

  3. #3
    Membre Expert
    Homme Profil pro
    Développeur .Net / Delphi
    Inscrit en
    Juillet 2002
    Messages
    738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Eure (Haute Normandie)

    Informations professionnelles :
    Activité : Développeur .Net / Delphi
    Secteur : Finance

    Informations forums :
    Inscription : Juillet 2002
    Messages : 738
    Par défaut
    Bonjour,

    As-tu essayé de modifier les paramètres de la fonction ligne 91 ?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     '
            ' Open Preview window in picturebox
            '
            hHwnd = capCreateCaptureWindowA(iDevice, WS_VISIBLE Or WS_CHILD, 0, 0, 640, _
                480, picCapture.Handle.ToInt32, 0)
    eb.

  4. #4
    Membre averti
    Homme Profil pro
    Inscrit en
    Janvier 2013
    Messages
    15
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations forums :
    Inscription : Janvier 2013
    Messages : 15
    Par défaut Déterrage de topic !!
    Bonjour à tous !
    Je galère toujours avec ma petite webcam mais j'avance!
    Dernier soucis en date: je dispose de deux webcams et elles n'apparaissent pas dans la liste mon programme.
    A l’exécution, une fenêtre de sélection s'ouvre,me propose le choix entre les deux caméras et me fait planter l'acquisition d'image.
    Quelqu'un à une solution ?????
    Merci d'avance !!!!

  5. #5
    Membre averti
    Homme Profil pro
    Inscrit en
    Janvier 2013
    Messages
    15
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations forums :
    Inscription : Janvier 2013
    Messages : 15
    Par défaut Solution !!
    Bon, je suis passé par AForge framework et ça marche au poil !!

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [Cal3D] Problème de compilation avec Cal3D sous windows
    Par nicoenz dans le forum Moteurs 3D
    Réponses: 2
    Dernier message: 15/11/2006, 09h46
  2. [CDT]C++ avec Eclipse sous Windows
    Par Invité dans le forum Eclipse Java
    Réponses: 8
    Dernier message: 22/10/2004, 08h32
  3. attaquer base sql server avec easyphp sous windows
    Par jarod71 dans le forum MS SQL Server
    Réponses: 7
    Dernier message: 11/12/2003, 14h17
  4. Besoin d'aide avec postgresql sous windows NT
    Par Chihuahua dans le forum PostgreSQL
    Réponses: 3
    Dernier message: 18/07/2003, 08h29
  5. Utiliser Borland C++ avec Emacs sous Windows
    Par Eikichi dans le forum Autres éditeurs
    Réponses: 2
    Dernier message: 02/03/2003, 08h40

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo