【发布时间】:2014-09-09 19:38:37
【问题描述】:
我有一个WPF 应用程序,它可以帮助我截取整个屏幕。
该应用程序包含一个带有按钮的小窗口,如果我单击该按钮,则会捕获屏幕截图并将其保存在我的驱动器上。
我想在捕获之前隐藏这个小窗口,所以它不会包含在捕获中,这是我尝试过的:
StartSnipping = new RelayCommand(() =>
{
// I hide it here !!
WindowVisibility = Visibility.Hidden;
//Than I take the screen shot
var screen = Screen.PrimaryScreen;
var bitmap = new Bitmap(screen.Bounds.Width, screen.Bounds.Height);
using (var graphics = Graphics.FromImage(bitmap))
{
graphics.CopyFromScreen(new Point(screen.Bounds.Left,
screen.Bounds.Top),
new Point(0, 0),
screen.Bounds.Size);
}
//I save the screen shot
bitmap.Save(@"C:/Users/Aymen/Desktop/test.png", ImageFormat.Png);
});
现在,假设这条线:
WindowVisibility = Visibility.Hidden;
确实有效,好吧,我确信这一点,因为在所有该方法完成运行之后,窗口确实被隐藏了。
假设屏幕截图已成功拍摄并保存并且仍然包含该窗口,该窗口应该在屏幕截图前 1 秒被隐藏,我的问题是:
为什么这个隐藏的窗口仍然出现在屏幕截图中??我应该怎么做才能让它不出现在屏幕截图中??
【问题讨论】:
-
//give it some time... Thread.Sleep()...- 请学会正确地做多线程。 -
@HighCore thx 的评论,这是我添加的一个绝望的东西,虽然现在删除了
-
很难猜到“WindowVisibility”可能意味着什么,没有同名的属性。 Windows 版本也很重要,Windows 8 对完全透明窗口的处理方式不同,并且您无法在早期版本中使用 CopyFromScreen() 捕获分层窗口。
-
@Hans:也许是这个? social.msdn.microsoft.com/Forums/vstudio/en-US/…
-
@HansPassant
WindowVisibility是ViewModel中的一个属性,Window 的 Visibility 属性绑定到该属性
标签: c# .net wpf windows window