以下方法取自WinForms应用程序。它只是捕获屏幕,但我需要修改它在WPF应用程序中工作。当我使用它时,它会返回一个黑色的图像。尺寸是正确的。我还没有任何开放的DirectX或视频,即使在我的桌面上也不行。WPF - Graphics.CopyFromScreen返回一个黑色图像
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;
}
任何人都可以用我的方式向我显示错误吗?
仍然无法正常工作,图像尺寸似乎正确,但整个图像是黑色的。谢谢,不过。 – user646265 2011-04-18 21:29:39