title: Implementing a WebCam on a WPF App using AForge.Net
body: <p>I'm writing an WPF application where I need to show a Webcam feed. I was able to do this easly with the AForge framework.But when I've changed from a computer to a another computer the same code doesn't work the same way. </p>
  
  <p>In the first one the webcam feed works perfectly, but in the other one this does't occur, the feed has a lot of delay, and the application doesn't work properly.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>    private void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
      {
          Bitmap img = (Bitmap)eventArgs.Frame.Clone();
  
          this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Render, (SendOrPostCallback)delegate
              {
                  IntPtr hBitmap = img.GetHbitmap();
                  System.Windows.Media.Imaging.BitmapSource bitmapSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
                      hBitmap,
                      IntPtr.Zero,
                      Int32Rect.Empty,
                      System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
  
                  DeleteObject(hBitmap);
  
                  img.Dispose();
                  GC.Collect();
                  image1.Source = bitmapSource;
  
              }, null);
  
      }
  </code></pre>
  
  <p>What this code is really simple, it gets a new_frame from the webcam in a form of a <code>Bitmap</code>, and what I need to do is to convert it to a <code>BitmapSource</code>, so I can show in the image frame of the WPF. I think this conversion is the responsible of the mess that is happening, but I don't understand why it works in a computer and in the other doesn't. </p>
  
  <p>The computer specs are almost the same, the processor is the same, as well the system memory.</p>
  
  <p>My problem here is about <strong>performance</strong>, this code in one computer runs smoothly, and the webcam feed is presented as it should, when I port it to another PC this doesn't happen.</p>