I was playing around with my webcam and started to create a small application (using the Microsoft Expression Encoder SDK), where the images of the webcam are streamed to a picturebox on a winform [1]. So far, everything went pretty smooth. But now my problem begins:
I want to capture a single image of the video stream and store it. I've found the "ScreenCaptureJob" class, which is able to create video files. Microsoft's MSDN states that it is possible to "capture anything from a still image of a dialog box" [2] to complete videos. All the samples in the MSDN refer to video capturing. Unfortunately I couldn't find any solution how to use this class to capture a single image.
Can anyone help me?
[1] Code to stream webcam to picture box (Source: http://www.codeproject.com/Articles/202464/How-to-use-a-WebCam-in-C-with-the-NET-Framework-4)
var lstVideoDevices = new Dictionary<string, EncoderDevice>();
var lstAudioDevices = new Dictionary<string, EncoderDevice>();
foreach (EncoderDevice edv in EncoderDevices.FindDevices(EncoderDeviceType.Video))
{
lstVideoDevices.Add(edv.Name, edv);
}
foreach (EncoderDevice eda in EncoderDevices.FindDevices(EncoderDeviceType.Audio))
{
lstAudioDevices.Add(eda.Name, eda);
}
_job = new
var _deviceSource = _job.AddDeviceSource(lstVideoDevices.Values.FirstOrDefault(x => x.Name.Contains("USB")), lstAudioDevices.Values.FirstOrDefault(x => x.Name.Contains("USB")));
_deviceSource.PreviewWindow = new PreviewWindow(new HandleRef(this.pictureBox1, this.pictureBox1.Handle));
_job.ActivateSource(_deviceSource);`
[2] http://msdn.microsoft.com/en-us/library/gg602440%28v=expression.40%29.aspx
I'm not sure if it's possible with Microsoft Expression Encoder SDK, it seems to be poorly documented.
But you can use Video Capture functions instead.
Just create a preview window using
capCreateCaptureWindow
function and then register frame callback using by sendingWM_CAP_SET_CALLBACK_FRAME
message:You can find C# examples here and here.
And if you figure out how to do that with Expression Encoder, please let me know.