I have a windows forms application written in C# which uses embedded Windows Media Player (AxInterop.WMPLib.dll and WMPLib.dll) to play some video files. Now I need to add an option to capture image from video on button click. If I set the windowless option to true, I am able to capture an image of a video, but when I set the windowless option to true I don't see a video image on some computers. Without the windowless option I only get a black screen with this code:
System.Drawing.Image ret = null;
try{
Bitmap bitmap = new Bitmap(wmPlayer.Width-26, wmPlayer.Height-66);
{
Graphics g = Graphics.FromImage(bitmap);
{
Graphics gg = wmPlayer.CreateGraphics();
{
this.BringToFront();
g.CopyFromScreen(
wmPlayer.PointToScreen(
new System.Drawing.Point()).X+13,
wmPlayer.PointToScreen(
new System.Drawing.Point()).Y,
0, 0,
new System.Drawing.Size(
wmPlayer.Width-26,
wmPlayer.Height-66)
);
}
}
using (MemoryStream ms = new MemoryStream()){
bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
ret = System.Drawing.Image.FromStream(ms);
ret.Save(@"C:\\WMP_capture.png");
pictureBox1.Image=ret;
}
}
bitmap.Dispose();
}catch (Exception){ }
How can I capture a frame (snapshot) from a video playing in embedded Windows Media Player without the windowless option in C#?
Or is there any other video player for C# windows forms that can be easily implemented and that supports capture functionality.
Hope this code work for you
}
One more demo for you : http://www.codeproject.com/Articles/34663/DirectShow-Examples-for-Using-SampleGrabber-for-Gr