简体   繁体   English

如何在C#中获取滚动窗口的屏幕截图

[英]How take screenshot of scrolling window in C#

What is the easiest way in C# to take a screenshot of a complete scrolling Window? 用C#拍摄完整滚动窗口的屏幕快照最简单的方法是什么?

I have sceen examples on here using a web browser, but in this case the window is a Windows desktop application. 我在这里使用Web浏览器浏览了许多示例,但是在这种情况下,该窗口是Windows桌面应用程序。

You can get windows to redirect a WM_PAINT to an offscreen buffer with WM_PRINT and WM_PRINTCLIENT. 您可以使用WM_PRINT和WM_PRINTCLIENT使Windows将WM_PAINT重定向到屏幕外缓冲区。 This is better than screenscraping because it makes sure that obscured parts of a window(behind other windows) is painted anyway. 这比屏幕抓取更好,因为它可以确保无论如何都绘制了窗口的遮盖部分(在其他窗口后面)。 If your target window scrolls by scrolling a child window position, WM_PRINT should apply. 如果您的目标窗口是通过滚动子窗口位置来滚动的,则应使用WM_PRINT。 Just maybe it also helps your scenario. 也许这也可以帮助您解决问题。

Just 3 lines of code is enough 只需三行代码就足够了

Bitmap b = new Bitmap(pnlOuter.Width, pnlOuter.Height);
pnlOuter.DrawToBitmap(b, new Rectangle(0, 0, pnlOuter.Width, pnlOuter.Height));
b.Save("D:\\bitmapImage.jpg");

pnlOuter is a panel that contains all the controls to be shown in image with extended height to contain all the inner controls. pnlOuter是一个面板,其中包含要在图像中显示的所有控件,并具有扩展的高度,以包含所有内部控件。 The containing form may have scroll bars enabled. 包含窗体可能启用了滚动条。

我通过使用Win API并拍摄了多个屏幕截图,在每个屏幕截图之间滚动然后将它们连接在一起来解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM