cdiego

obtener imagenes de webcam con C#

Sep 19th, 2013
2,615
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.87 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using AForge.Video;
  10. using AForge.Video.DirectShow;
  11.  
  12. namespace WindowsFormsApplication1
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.         //AGREGAR REFERENCIAS
  17.         //AGREGAR CONTROLES
  18.         //DISEÑAR FORMULARIO
  19.         // VideoSourcePlayer1 es el control donde se mostrará
  20.         //la imagen de la webcam
  21.         public Form1()
  22.         {
  23.             InitializeComponent();
  24.         }
  25.         //AGREGAR USING
  26.         //VARIABLE PARA LISTA DE DISPOSITIVOS
  27.         private FilterInfoCollection Dispositivos;
  28.         //VARIABLE PARA FUENTE DE VIDEO
  29.         private VideoCaptureDevice FuenteDeVideo;
  30.  
  31.         private void Form1_Load(object sender, EventArgs e)
  32.         {
  33.             //LISTAR DISPOSITIVOS DE ENTRADA DE VIDEO
  34.             Dispositivos = new FilterInfoCollection(FilterCategory.VideoInputDevice);
  35.             //CARGAR TODOS LOS DISPOSITIVOS AL COMBO
  36.             foreach (FilterInfo x in Dispositivos)
  37.             {
  38.                 comboBox1.Items.Add(x.Name);
  39.             }
  40.             comboBox1.SelectedIndex = 0;
  41.         }
  42.  
  43.         private void button1_Click(object sender, EventArgs e)
  44.         {
  45.             //ESTABLECER EL DISPOSITIVO SELECCIONADO COMO FUENTE DE VIDEO
  46.             FuenteDeVideo = new VideoCaptureDevice(Dispositivos[comboBox1.SelectedIndex].MonikerString);
  47.             //INICIALIZAR EL CONTROL
  48.             videoSourcePlayer1.VideoSource = FuenteDeVideo;
  49.             //INICIAR RECEPCION DE IMAGENES
  50.             videoSourcePlayer1.Start();
  51.         }
  52.  
  53.         private void button2_Click(object sender, EventArgs e)
  54.         {
  55.             //DETENER RECEPCION DE IMAGENES
  56.             videoSourcePlayer1.SignalToStop();
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment