Get Webcam stream using Aforge.NET in C# and WPF

前端 未结 2 1182
失恋的感觉
失恋的感觉 2021-02-14 13:18

I want to capture a webcam feed using my camera. For that I am using the 2 references: AForge.Video.dll and AForge.Video.DirectShow.dll.

Here\'

相关标签:
2条回答
  • 2021-02-14 13:43

    Edit1: for a detailed explanation view my blogpost on the same topic.


    I fixed the error using the Dispatcher class as a mutex:

    void Cam_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
    
            System.Drawing.Image imgforms = (Bitmap)eventArgs.Frame.Clone(); 
    
            BitmapImage bi = new BitmapImage(); 
            bi.BeginInit(); 
    
            MemoryStream ms = new MemoryStream(); 
            imgforms.Save(ms, ImageFormat.Bmp); 
            ms.Seek(0, SeekOrigin.Begin); 
    
            bi.StreamSource = ms; 
            bi.EndInit();
    
            //Using the freeze function to avoid cross thread operations 
            bi.Freeze();
    
            //Calling the UI thread using the Dispatcher to update the 'Image' WPF control         
            Dispatcher.BeginInvoke(new ThreadStart(delegate
            {
                frameholder.Source = bi; /*frameholder is the name of the 'Image' WPF control*/
            }));     
    
        }
    

    Now it runs as expected and I get good performance without any drop in the fps.

    0 讨论(0)
  • 2021-02-14 13:51

    If you want to support Silverlight, be it for web or standalone or WP7, you shouldn't start with WPF, as many features from WPF are lacking in Silverlight.

    Here is a Silverlight 4+ tutorial:

    http://www.silverlightshow.net/items/Capturing-the-Webcam-in-Silverlight-4.aspx

    0 讨论(0)
提交回复
热议问题