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!
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!