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
| Imports DirectX.Capture
Public Class Form4
Inherits System.Windows.Forms.Form
Dim NombreDeCapture As Int16
Dim TimeElapsCapture As Integer
Dim StartTime As Date
Dim j As Short
Dim f As Filter
Private Sub Form4_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
If Button1.Enabled = False Then
CaptureInformation2.CaptureInfo.DisposeCapture()
Me.Dispose()
End If
End Sub
Private Sub Form4_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
'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
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'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 = PictureBox2
'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
End Sub
Private Sub Configurer()
'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()
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
'' histoire de savoir combien ca prends de temps de faire une capture.
Dim RunLength As System.TimeSpan = Now.Subtract(StartTime)
Dim TimeElapsCapture As Integer = RunLength.Milliseconds
Label1.Visible = False
NombreDeCapture = NombreDeCapture + 1
Label1.Text = "Capture nmr:" & NombreDeCapture & " Capture realisée en:" & TimeElapsCapture & " ms"
PictureBox1.Image = la.Image 'j affecte ma capture d'image a mon picturebox qui attend que ca.
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
'demande une capture DirectX ...et lorsqu'elle est ready je la recoit par le Handler cree un peut plus haut
Dim StartTime As Date = Now ' Starting date/time.
CaptureInformation2.CaptureInfo.CaptureFrame()
Button2.Enabled = True
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
PictureBox1.Image.Save("d:\essai\image\" & Form2.Txtnom.Text & ".jpg")
Form2.PictureBox1.Image = System.Drawing.Image.FromFile("d:\essai\image\" & Form2.Txtnom.Text & ".jpg")
CaptureInformation2.CaptureInfo.DisposeCapture()
Me.Dispose()
End Sub |
Partager