cdiego

tomar foto con webcam C# y aforge

Nov 25th, 2013
2,445
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.80 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.DirectShow;
  10. namespace WindowsFormsApplication1
  11. {
  12.     public partial class Form1 : Form
  13.     {
  14.         public Form1()
  15.         {
  16.             InitializeComponent();
  17.         }
  18.         private FilterInfoCollection Dispositivos; //LISTA DE DISPOSITIVOS
  19.         private VideoCaptureDevice FuenteDeVideo; //DISPOSITIVO QUE USAREMOS COMO FUENTE
  20.        
  21.         private void Form1_Load(object sender, EventArgs e)
  22.         {
  23.             //LISTAR DISPOSITIVOS DE ENTRADAS DE VIDEO
  24.             Dispositivos = new FilterInfoCollection(FilterCategory.VideoInputDevice);
  25.             //Dispositivos tiene el array, con todos los dispositivos disponibles
  26.             foreach (FilterInfo x in Dispositivos)
  27.             {
  28.                 comboBox1.Items.Add(x.Name);
  29.             }
  30.             comboBox1.SelectedIndex = 0;
  31.         }
  32.  
  33.         private void button1_Click(object sender, EventArgs e)
  34.         {
  35.             //ESTABLECER EL DISPOSITIVO SELECCIONADO COMO FUENTE DE VIDEO
  36.             FuenteDeVideo = new VideoCaptureDevice(Dispositivos[comboBox1.SelectedIndex].MonikerString);
  37.             //INICIALIZAR EL CONTROL
  38.             videoSourcePlayer1.VideoSource = FuenteDeVideo;
  39.             //INICIAR LA RECEPCIÓN DE IMAGENES
  40.             videoSourcePlayer1.Start();
  41.         }
  42.  
  43.         private void button2_Click(object sender, EventArgs e)
  44.         {
  45.             //DETENER LA RECEPCIÓN DE IMAGENES
  46.             videoSourcePlayer1.SignalToStop();
  47.         }
  48.  
  49.         private void videoSourcePlayer1_Click(object sender, EventArgs e)
  50.         {
  51.            
  52.         }
  53.  
  54.         private void videoSourcePlayer1_NewFrame(object sender, ref Bitmap image)
  55.         {
  56.            
  57.         }
  58.  
  59.         private void button3_Click(object sender, EventArgs e)
  60.         {
  61.            
  62.            
  63.         }
  64.  
  65.         private void button3_Click_1(object sender, EventArgs e)
  66.         {
  67.             //DIALOGO PARA SELECCIONAR LA RUTA PARA GUARDAR
  68.             SaveFileDialog sf = new SaveFileDialog();
  69.             //FILTO DE IMAGENES JPG
  70.             sf.Filter = "Imagenes JPG | *.jpg";
  71.             //MOSTRAR DIALOGO
  72.             sf.ShowDialog();
  73.             //ASEGURAR QUE TIENE UNA RUTA VALIDA
  74.             if (sf.FileName != null)
  75.             {
  76.                 //VARIBALE PARA LA IMAGEN
  77.                 Bitmap img = videoSourcePlayer1.GetCurrentVideoFrame();
  78.                 //GUARDAR IMAGEN EN LA RUTA
  79.                 img.Save(sf.FileName, System.Drawing.Imaging.ImageFormat.Jpeg);
  80.                 //BORRAR IMAGEN DE MEMORIA
  81.                 img.Dispose();
  82.                 //PROBAR!
  83.             }
  84.         }
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment