【问题标题】:take snapshot with c# (AForge)使用 c# (AForge) 拍摄快照
【发布时间】:2017-05-12 15:40:25
【问题描述】:

我用 AForge 编写了这段代码。输出应该是使用 Wabcam 拍摄的图片(保存在“C:\users\me\Desktop\Picture.jpg”中)。 代码只是不这样做,我不知道为什么。谢谢

    static void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
    {
        Bitmap bitmap = (Bitmap)eventArgs.Frame.Clone();
        bitmap.Save(@"c:\users\me\desktop\picture.jpg");
       }
    static void Main(string[] args)
    {
        FilterInfoCollection videoDevices = new FilterInfoCollection( FilterCategory.VideoInputDevice );            VideoCaptureDevice videoSource = new VideoCaptureDevice( videoDevices[0].MonikerString );
        videoSource.NewFrame += new NewFrameEventHandler( video_NewFrame );
        videoSource.Start();
        videoSource.SignalToStop();

    }

【问题讨论】:

    标签: c# image webcam aforge


    【解决方案1】:

    试试这个:

        public static  bool x = false;
        static void Main(string[] args)
        {
            FilterInfoCollection videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); VideoCaptureDevice videoSource = new VideoCaptureDevice(videoDevices[0].MonikerString);
            videoSource.NewFrame += new NewFrameEventHandler(video_NewFrame);
            videoSource.Start();
            while (true)
            {
                if (x == true)
                {
                    videoSource.SignalToStop();
                    break;
                }
            }
        }
        static void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            Bitmap bitmap = (Bitmap)eventArgs.Frame.Clone();
            bitmap.Save(@"C:\Users\Skydr\Desktop\C++_Project\a.jpg");
            x = true;
        }
    

    【讨论】:

    • 您的问题是在未完成接收帧时调用“SignalToStop”。该代码让相机接收到图片然后关闭视频源而不会被中断。
    【解决方案2】:

    谢谢阿多拉,我解决了这样的问题:

         static void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            Bitmap bitmap = (Bitmap)eventArgs.Frame;
            bitmap.Save(@"c:\users\me\desktop\picture.jpg");
    
    
    
        static void Main(string[] args)
        {
            bool finish = false ;
            FilterInfoCollection videoDevices = new FilterInfoCollection( FilterCategory.VideoInputDevice );
             VideoCaptureDevice videoSource = new VideoCaptureDevice( videoDevices[0].MonikerString );
            videoSource.NewFrame += new NewFrameEventHandler( video_NewFrame );
            videoSource.Start();
            do{
            if (File.Exists(@"c:\users\me\desktop\picture.jpg"))
            {
                finish = true;
            videoSource.SignalToStop();
           }
            } while (finish != true);
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-02-14
      • 2014-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-03
      相关资源
      最近更新 更多