以下方法取自 WinForms 应用程序。它只是捕获屏幕,但我需要修改它才能在 WPF 应用程序中工作。当我使用它时,它返回黑色图像。尺寸正确。我没有任何打开的 DirectX 或视频,甚至在我的桌面上也无法工作。
public static Bitmap CaptureScreen()
{
// Set up a bitmap of the correct size
Bitmap CapturedImage = new Bitmap((int)SystemParameters.VirtualScreenWidth,
(int)SystemParameters.VirtualScreenHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
// Create a graphics object from it
System.Drawing.Size size = new System.Drawing.Size((int)SystemParameters.VirtualScreenWidth, (int)SystemParameters.VirtualScreenHeight);
using (Graphics g = Graphics.FromImage(CapturedImage))
{
// copy the entire screen to the bitmap
g.CopyFromScreen((int)SystemParameters.VirtualScreenWidth, (int)SystemParameters.VirtualScreenHeight, 0, 0,
size, CopyPixelOperation.SourceCopy);
}
return CapturedImage;
}
谁能告诉我我的方法有错误吗?
我相信您需要使用 Interop 和 BitBlt 方法。这个博客 http://10rem.net/blog/2011/02/08/capturing-screen-images-in-wpf-using-gdi-win32-and-a-little-wpf-interop-help解释了这是如何完成的,并且后续帖子 http://10rem.net/blog/2011/02/09/enhancing-the-wpf-screen-capture-program-with-window-borders显示如何获取窗口边框。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)