1

I need to capture an image form a WebCam. I'm using WPFMediaKit (WPFMediaKit on GitHub), and I can see the webcam video, but I don't found how to take an snapshot.

<controls:VideoCaptureElement x:Name="videoCapElement"
                             LoadedBehavior="Play"
                             DesiredPixelWidth="320"
                             DesiredPixelHeight="240"
                             Stretch="Fill"
                             VideoCaptureSource="Camera Name"
                             FPS="30"/>

Thanks for yout time!

xmedeko
  • 7,336
  • 6
  • 55
  • 85
Duefectu
  • 1,563
  • 4
  • 18
  • 37

1 Answers1

4

I found the solution in this page: Jason's C# Coding Record -> Capture a photo via WPFMediaKit

Extract:

private void btnCapture_Click(object sender, RoutedEventArgs e)
{     
  RenderTargetBitmap bmp = new RenderTargetBitmap((int)captureElement.ActualWidth, (int)captureElement.ActualHeight, 96, 96, 
       PixelFormats.Default);
  bmp.Render(captureElement);
  BitmapEncoder encoder = new JpegBitmapEncoder();
  encoder.Frames.Add(BitmapFrame.Create(bmp));
  using (MemoryStream ms = new MemoryStream())
  {
       encoder.Save(ms);
       CaptureData = ms.ToArray();
  }
  DialogResult = true;
}

Thnaks for your time!

djunod
  • 4,876
  • 2
  • 34
  • 28
Duefectu
  • 1,563
  • 4
  • 18
  • 37