我试图在Windows 7 64位的进程窗口截图,问题是我总是在以下行中得到错误:
var bmp = new Bitmap (width, height, PixelFormat.Format32bppArgb);
Run Code Online (Sandbox Code Playgroud)
说"无效参数",我抛出一个看错误,宽度和高度始终为0.
在32位之前它运行良好,但现在在64位中它不再起作用.
代码 :
public void CaptureApplication()
{
string procName = "firefox";
var proc = Process.GetProcessesByName(procName)[0];
var rect = new User32.Rect();
User32.GetWindowRect(proc.MainWindowHandle, ref rect);
int width = rect.right - rect.left;
int height = rect.bottom - rect.top;
var bmp = new Bitmap(width, height, PixelFormat.Format32bppArgb);
Graphics graphics = Graphics.FromImage(bmp);
graphics.CopyFromScreen(rect.left, rect.top, 0, 0, new Size(width, height), CopyPixelOperation.SourceCopy);
bmp.Save("c:\\tmp\\test.png", ImageFormat.Png);
}
private class User32
{
[StructLayout(LayoutKind.Sequential)]
public struct Rect
{
public int …Run Code Online (Sandbox Code Playgroud) c# ×1