CSHARP 33
CamCap Guest on 25th October 2019 11:44:33 AM
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using AForge.Video;
  7. using AForge.Video.DirectShow;
  8. using System.Drawing;
  9.  
  10. namespace CamCap2
  11. {
  12.  
  13.  
  14.     class Program
  15.     {
  16.         static FilterInfoCollection WebcamColl;
  17.         static VideoCaptureDevice Device;
  18.         static string CaptureFileName;
  19.         static void Capture(int cameraIndex = 0)
  20.         {
  21.             WebcamColl = new FilterInfoCollection(FilterCategory.VideoInputDevice);
  22.             Device = new VideoCaptureDevice(WebcamColl[cameraIndex].MonikerString);
  23.             Device.Start();
  24.             Device.NewFrame += new NewFrameEventHandler(Cam_SnapshotTaken);
  25.         }
  26.  
  27.         static int Main(string[] args)
  28.         {
  29.  
  30.             if (args == null)
  31.             {
  32.                 Console.WriteLine("args is null");
  33.             }
  34.             else
  35.             {
  36.                 Console.Write("args length is ");
  37.                 Console.WriteLine(args.Length);
  38.                 for (int i = 0; i < args.Length; i++)
  39.                 {
  40.                     string argument = args[i];
  41.                     if (argument.ToLower() == "-filename")
  42.                     {
  43.                         var watch = System.Diagnostics.Stopwatch.StartNew();
  44.                         Console.WriteLine("Your file will be saved in: " + args[i + 1]);
  45.                         CaptureFileName = args[i + 1];
  46.                         Capture();
  47.                         watch.Stop();
  48.                         var elapsedMs = watch.ElapsedMilliseconds;
  49.                         Console.WriteLine("Executed in " + elapsedMs + "ms");
  50.                         return 0;
  51.                     }
  52.                 }
  53.             }
  54.             //Console.ReadLine();
  55.             return 0;
  56.            
  57.         }
  58.  
  59.         static void Cam_SnapshotTaken(object sender, NewFrameEventArgs eventArgs)
  60.         {
  61.             Image img = (Bitmap)eventArgs.Frame.Clone();
  62.             img.Save(@CaptureFileName);
  63.             Device.SignalToStop();
  64.         }
  65.     }
  66. }

RSO cPaste е място за публикуване на код или текст за по-лесно отстраняване на грешки.

Влез или се Регистрай за да редактираш, изтриваш или преглеждаш хронология на твоето публикувано съдържание

Необработен текст

Влез или се Регистрирай за да редактираш или задържиш това съдържание.