【发布时间】:2011-08-08 05:10:31
【问题描述】:
以下方法取自 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;
}
谁能以我的方式告诉我错误?
【问题讨论】:
标签: c# wpf graphics bitmap screenshot