C#Windows窗体捕获从嵌入式的Windows Media Player中的形象 [英] C# Windows Forms capture a image from embeded Windows Media Player
问题描述
我有一个Windows窗体应用程序编写中采用嵌入式的Windows Media Player(AxInterop.WMPLib.dll和WMPLib.dll)C#播放一些视频文件。现在我需要添加一个选项从视频捕获图像按钮的点击。如果我设置了窗户的选项设置为true,我能够捕获视频的图像,但是当我的窗户选项设置为true我没有看到在某些计算机视频图像。没有窗户的选项我只得到一个黑色的屏幕与此代码:
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){ }
我怎么能捕获帧从视频中嵌入的Windows Media Player中播放无窗户的选项在C#(快照)?
How can I capture a frame (snapshot) from a video playing in embedded Windows Media Player without the windowless option in C#?
或者是有C#Windows窗体任何其他视频播放器,可以轻松实现并支持拍摄功能。
Or is there any other video player for C# windows forms that can be easily implemented and that supports capture functionality.
推荐答案
希望你此代码的工作。
if (!string.IsNullOrEmpty(axWindowsMediaPlayer1.URL)){
axWindowsMediaPlayer1.Ctlcontrols.pause();
System.Drawing.Image ret = null;
try
{
// take picture BEFORE saveFileDialog pops up!!
Bitmap bitmap = new Bitmap(axWindowsMediaPlayer1.Width, axWindowsMediaPlayer1.Height);
{
Graphics g = Graphics.FromImage(bitmap);
{
Graphics gg = axWindowsMediaPlayer1.CreateGraphics();
{
//timerTakePicFromVideo.Start();
this.BringToFront();
g.CopyFromScreen(
axWindowsMediaPlayer1.PointToScreen(
new System.Drawing.Point()).X,
axWindowsMediaPlayer1.PointToScreen(
new System.Drawing.Point()).Y,
0, 0,
new System.Drawing.Size(
axWindowsMediaPlayer1.Width,
axWindowsMediaPlayer1.Height)
);
}
}
// afterwards save bitmap file if user wants to
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
using (MemoryStream ms = new MemoryStream())
{
bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
ret = System.Drawing.Image.FromStream(ms);
ret.Save(saveFileDialog1.FileName);
}
}
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
}
}
HTTP:你还有一个演示// WWW .codeproject.com /用品/ 34663 / DirectShow的例子换用-SampleGrabber换-GR
这篇关于C#Windows窗体捕获从嵌入式的Windows Media Player中的形象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!