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 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
|
Imports DirectX.Capture
Imports System.Drawing
Imports System.Drawing.Imaging
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Code généré par le Concepteur Windows Form "
Public Sub New()
MyBase.New()
'Cet appel est requis par le Concepteur Windows Form.
InitializeComponent()
'Ajoutez une initialisation quelconque après l'appel InitializeComponent()
End Sub
'La méthode substituée Dispose du formulaire pour nettoyer la liste des composants.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Requis par le Concepteur Windows Form
Private components As System.ComponentModel.IContainer
'REMARQUE*: la procédure suivante est requise par le Concepteur Windows Form
'Elle peut être modifiée en utilisant le Concepteur Windows Form.
'Ne la modifiez pas en utilisant l'éditeur de code.
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox
Friend WithEvents ComboBox2 As System.Windows.Forms.ComboBox
Friend WithEvents PicCam As System.Windows.Forms.PictureBox
Friend WithEvents CmdCapture As System.Windows.Forms.Button
Friend WithEvents PicCapture As System.Windows.Forms.PictureBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Form1))
Me.Button1 = New System.Windows.Forms.Button
Me.PicCapture = New System.Windows.Forms.PictureBox
Me.ComboBox1 = New System.Windows.Forms.ComboBox
Me.ComboBox2 = New System.Windows.Forms.ComboBox
Me.PicCam = New System.Windows.Forms.PictureBox
Me.CmdCapture = New System.Windows.Forms.Button
CType(Me.PicCapture, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.PicCam, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(16, 379)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(75, 23)
Me.Button1.TabIndex = 1
Me.Button1.Text = "Valider la configuration"
Me.Button1.Visible = False
'
'PicCapture
'
Me.PicCapture.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.PicCapture.Location = New System.Drawing.Point(443, 327)
Me.PicCapture.Name = "PicCapture"
Me.PicCapture.Size = New System.Drawing.Size(111, 90)
Me.PicCapture.TabIndex = 7
Me.PicCapture.TabStop = False
Me.PicCapture.Visible = False
'
'ComboBox1
'
Me.ComboBox1.FormattingEnabled = True
Me.ComboBox1.Location = New System.Drawing.Point(16, 327)
Me.ComboBox1.Name = "ComboBox1"
Me.ComboBox1.Size = New System.Drawing.Size(76, 21)
Me.ComboBox1.TabIndex = 9
Me.ComboBox1.Visible = False
'
'ComboBox2
'
Me.ComboBox2.FormattingEnabled = True
Me.ComboBox2.Location = New System.Drawing.Point(16, 354)
Me.ComboBox2.Name = "ComboBox2"
Me.ComboBox2.Size = New System.Drawing.Size(75, 21)
Me.ComboBox2.TabIndex = 10
Me.ComboBox2.Visible = False
'
'PicCam
'
Me.PicCam.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.PicCam.Location = New System.Drawing.Point(12, 12)
Me.PicCam.Name = "PicCam"
Me.PicCam.Size = New System.Drawing.Size(489, 398)
Me.PicCam.TabIndex = 12
Me.PicCam.TabStop = False
'
'CmdCapture
'
Me.CmdCapture.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.CmdCapture.Image = CType(resources.GetObject("CmdCapture.Image"), System.Drawing.Image)
Me.CmdCapture.Location = New System.Drawing.Point(517, 11)
Me.CmdCapture.Name = "CmdCapture"
Me.CmdCapture.Size = New System.Drawing.Size(142, 405)
Me.CmdCapture.TabIndex = 11
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.BackColor = System.Drawing.Color.FromArgb(CType(CType(225, Byte), Integer), CType(CType(233, Byte), Integer), CType(CType(241, Byte), Integer))
Me.ClientSize = New System.Drawing.Size(677, 428)
Me.Controls.Add(Me.CmdCapture)
Me.Controls.Add(Me.ComboBox2)
Me.Controls.Add(Me.ComboBox1)
Me.Controls.Add(Me.PicCapture)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.PicCam)
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "Form1"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "PRENDRE UNE PHOTO"
CType(Me.PicCapture, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.PicCam, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim j As Short
Dim f As Filter
Try
'listage des peripheriques video installés sur la machine
ComboBox1.Items.Clear()
For j = 0 To Dispositivos.VideoInputDevices.Count - 1
f = Dispositivos.VideoInputDevices(j)
ComboBox1.Items.Add(f.Name)
Next
If j > 0 Then ComboBox1.SelectedIndex = 0
'listage des peripheriques audio installés sur la machine
ComboBox2.Items.Clear()
For j = 0 To Dispositivos.AudioInputDevices.Count - 1
f = Dispositivos.AudioInputDevices(j)
ComboBox2.Items.Add(f.Name)
Next
If j > 0 Then ComboBox2.SelectedIndex = 0
'pre configuration du capturing
'definission de la camera
CaptureInformation2.Camera = Dispositivos.VideoInputDevices(ComboBox1.SelectedIndex)
'mise en place du stream video et audio
CaptureInformation2.CaptureInfo = New DirectX.Capture.Capture(CaptureInformation2.Camera, Dispositivos.AudioInputDevices(ComboBox2.SelectedIndex))
'renseignement du panneau d'affichage de la video
CaptureInformation2.CaptureInfo.PreviewWindow = PicCam
'compteur pour les capture d'image (frame video)
CaptureInformation2.Counter = 1
CaptureInformation2.CounterFrames = 1
'configurations avancées
Configurer()
'pour faire plus joli
Button1.Enabled = False
'pour la gestion evennementiel de la capture d'ecran je cree un gestionnaire d evennement sur Framecapturecomplete
AddHandler CaptureInformation2.CaptureInfo.FrameCaptureComplete, AddressOf NewCaptureReady
Catch ex As Exception
MsgBox(ex.Message)
End
End Try
End Sub
Private Sub Configurer()
Try
'configurations avancées
'configuration du systeme de compression video et audio
CaptureInformation2.CaptureInfo.VideoCompressor = Dispositivos.VideoCompressors(1) 'compression video
'taille de la video
CaptureInformation2.CaptureInfo.FrameSize = New Size(320, 240) 'taille de la video
'FPS de la video
CaptureInformation2.CaptureInfo.FrameRate = 50 'FPS
'fichier .avi
''CaptureInformation.CaptureInfo.Filename = Application.StartupPath + "\essai.avi"
'lancement du streaming d'affichage
CaptureInformation2.CaptureInfo.RenderPreview()
Catch ex As Exception
MsgBox(ex.Message)
End
End Try
End Sub
Private Sub NewCaptureReady(ByVal Sender As System.Windows.Forms.PictureBox)
'appele par le gestionnaire de handler sur l'evennement "FrameCapture
'ma picture capturé est arrivée...
Dim la As PictureBox = CType(Sender, PictureBox) 'la je converti mon picturebox en picturebox...je sais pas pourquoi, fo le faire sinom ca marche pas
Try
PicCapture.Image = la.Image 'j affecte ma capture d'image a mon picturebox qui attend que ca.
Catch ex As Exception
MsgBox(ex.Message)
End
End Try
End Sub
Sub Tue(ByVal Chem As String)
Try
My.Computer.FileSystem.DeleteFile(Chem)
Catch ex As Exception
'rien
End Try
End Sub
Private Sub CmdCapture_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdCapture.Click
Try
'demande une capture DirectX ...et lorsqu'elle est ready je la recoit par le Handler cree un peut plus haut
CaptureInformation2.CaptureInfo.CaptureFrame()
Tue(System.AppDomain.CurrentDomain.BaseDirectory() & "WCcapture.jpg")
Do While PicCapture.Image Is Nothing
Application.DoEvents()
Loop
PicCapture.Image.Save(System.AppDomain.CurrentDomain.BaseDirectory() & "WCcapture.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
Catch ex As Exception
MsgBox(ex.Message.ToString, MsgBoxStyle.Critical, "impossible d'enregister l'image")
End Try
End
End Sub
End Class |
Partager