Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using AForge.Video.DirectShow;
- using AForge.Video;
- using System.Drawing;
- using System.Drawing.Imaging;
- namespace WebCam_Screenshot
- {
- public class WebCamHandler
- {
- private FilterInfoCollection videoDevices;
- private VideoCaptureDevice videoSource;
- private Bitmap lastFrame;
- public WebCamHandler()
- {
- videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
- videoSource = new VideoCaptureDevice(videoDevices[0].MonikerString);
- videoSource.NewFrame += new NewFrameEventHandler(video_NewFrame);
- }
- public void getImage()
- {
- videoSource.Start();
- // Busy form of waiting
- while (lastFrame == null)
- ; // no-op
- videoSource.SignalToStop();
- videoSource.WaitForStop();
- }
- private void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
- {
- lastFrame = eventArgs.Frame;
- lastFrame.Save("C:\\Users\\samue\\Documents\\immagini webcam\\img.png", ImageFormat.Png);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement