Advertisement
informaticage

Webcam shot

Jan 22nd, 2023
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. using System;
  2. using AForge.Video.DirectShow;
  3. using AForge.Video;
  4. using System.Drawing;
  5. using System.Drawing.Imaging;
  6.  
  7. namespace WebCam_Screenshot
  8. {
  9. public class WebCamHandler
  10. {
  11. private FilterInfoCollection videoDevices;
  12. private VideoCaptureDevice videoSource;
  13. private Bitmap lastFrame;
  14.  
  15. public WebCamHandler()
  16. {
  17. videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
  18. videoSource = new VideoCaptureDevice(videoDevices[0].MonikerString);
  19. videoSource.NewFrame += new NewFrameEventHandler(video_NewFrame);
  20. }
  21.  
  22. public void getImage()
  23. {
  24. videoSource.Start();
  25.  
  26. // Busy form of waiting
  27. while (lastFrame == null)
  28. ; // no-op
  29.  
  30. videoSource.SignalToStop();
  31. videoSource.WaitForStop();
  32. }
  33.  
  34. private void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
  35. {
  36.  
  37. lastFrame = eventArgs.Frame;
  38. lastFrame.Save("C:\\Users\\samue\\Documents\\immagini webcam\\img.png", ImageFormat.Png);
  39. }
  40. }
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement