Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.36 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.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using AForge;
  11. using AForge.Video;
  12. using AForge.Video.DirectShow;
  13.  
  14. namespace WindowsFormsApp1
  15. {
  16.     public partial class Form1 : Form
  17.     {
  18.         public Form1()
  19.         {
  20.             InitializeComponent();
  21.         }
  22.  
  23.         private FilterInfoCollection capture;
  24.         private VideoCaptureDevice source;
  25.  
  26.         private void Form1_Load(object sender, EventArgs e)
  27.         {
  28.             capture = new FilterInfoCollection(FilterCategory.VideoInputDevice);
  29.             foreach(FilterInfo Device in capture)
  30.             {
  31.                 comboBox1.Items.Add(Device.Name);
  32.             }
  33.             comboBox1.SelectedIndex = 0;
  34.             source = new VideoCaptureDevice();
  35.         }
  36.  
  37.         private void button1_Click(object sender, EventArgs e)
  38.         {
  39.             source = new VideoCaptureDevice(capture[comboBox1.SelectedIndex].MonikerString);
  40.             source.NewFrame += new NewFrameEventHandler(VideoSource_NewFrame);
  41.             source.Start();
  42.         }
  43.  
  44.         private void VideoSource_NewFrame(object sender, NewFrameEventArgs e)
  45.         {
  46.             pictureBox1.Image = (Bitmap)e.Frame.Clone();
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement