C#如何获得窗口的屏幕截图?

C#如何获得窗口的屏幕截图?,c#,window,screenshot,C#,Window,Screenshot,我用这个方法得到了一张全屏截图 Bitmap bitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb); using (Graphics graphics = Graphics.FromImage(bitma

我用这个方法得到了一张全屏截图

Bitmap bitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
                           Screen.PrimaryScreen.Bounds.Height,
                           PixelFormat.Format32bppArgb);

using (Graphics graphics = Graphics.FromImage(bitmap))
{
     graphics.CopyFromScreen(Screen.PrimaryScreen.Bounds.X,
         Screen.PrimaryScreen.Bounds.Y,
         0, 0, Screen.PrimaryScreen.Bounds.Size,
         CopyPixelOperation.SourceCopy);
}
现在我想做的是改进这一点,我可以得到一些特定窗口的截图

我只知道几件事:

  • 标题
  • 创建它的主进程(此进程可以创建数量不确定的窗口)
  • 它不一定是活动窗口


    非常感谢您的帮助。

    您有车窗把手吗@说如果他没有,他可以在窗口中循环找到正确的一个。@newStackExchangeInstance-我知道,我只是指出了正确的方向:)我故意忽略了这一点,因为如果窗口句柄已经可用,这是一种懒惰的方法。我认为您必须使用Windows API找到您感兴趣的窗口句柄,然后从那里开始。谢谢Matthew,这似乎很有效。