c#活动窗口的屏幕截图,但没有';t遮住窗户
本文关键字:窗户 窗口 活动 屏幕截图 | 更新日期: 2023-09-27 18:25:26
我正在创建一个应用程序,需要在其中创建一个带有应用程序屏幕截图的PDF文件。
我找到了如何创建屏幕截图以及如何将其放入我的文件中。在大多数情况下,一切都很顺利。
当我使用多个屏幕或像Teamviewer这样的程序时,我的问题就来了。问题是,我的程序捕捉到了正确的区域(无论哪个屏幕,屏幕上都有很好的坐标),但它捕捉到了窗口后面的所有内容,而不是窗口。
有人知道我做错了什么,或者我错过了一个细节吗?
这是我目前使用的代码:
// creates an rectangle of the size of the window
Rectangle bounds = new Rectangle(
(int)System.Windows.Application.Current.MainWindow.Left+10,
(int)System.Windows.Application.Current.MainWindow.Top+10,
(int)System.Windows.Application.Current.MainWindow.Width-20,
(int)System.Windows.Application.Current.MainWindow.Height-20);
// creates a bitmap with a screenshot of the size of the window
Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height);
Graphics g = Graphics.FromImage(bitmap);
g.CopyFromScreen(new System.Drawing.Point(bounds.Left, bounds.Top), new System.Drawing.Point(0,0), bounds.Size);
提前感谢您的帮助或示例。
我不完全理解你。我认为你需要做的就是捕捉活动窗口。
Rectangle bounds = Screen.GetBounds(Point.Empty);
using(Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
{
using(Graphics g = Graphics.FromImage(bitmap))
{
g.CopyFromScreen(Point.Empty, Point.Empty, bounds.Size);
}
bitmap.Save("test.jpg", ImageFormat.Jpeg);
}
//for capturing current window use
Rectangle bounds = this.Bounds;
using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
{
using (Graphics g = Graphics.FromImage(bitmap))
{
g.CopyFromScreen(new Point(bounds.Left,bounds.Top), Point.Empty, bounds.Size);
}
bitmap.Save("C://test.jpg", ImageFormat.Jpeg);
}
来源:捕获活动窗口的屏幕截图?