Linux:启动窗口、捕获屏幕
我需要编写一个 Red Hat Linux 命令行工具来启动一个窗口并将其外观以 JPEG 格式捕获到磁盘。
通常目标机器没有显卡,但我们可以安装任何软件组件(例如X)。
一两个问题:
您可能会建议使用哪些库或工具?
如果我使用 GTK+ 之类的东西来创建这个工具,缺少显卡会妨碍它的执行吗?
我看到了 scrot
,但它似乎不支持在没有用户交互的情况下捕获特定窗口。
I need to write a Red Hat Linux command line tool that launches a window and captures its appearance to disk as a JPEG.
Typically the target machines don't have graphics cards, but we can install any software components (e.g., X).
Question or two:
What libraries or tools might you suggest for this?
If I were to use something like GTK+ to create this tool, would lacking a video card hamper its execution?
I saw scrot
, but it doesn't appear to support capturing a specific window without user interaction.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听起来您需要使用“虚拟帧缓冲区” X.org 服务器驱动程序,与 xwd 结合使用,NetPBM 和 cjpeg 实用程序。
我不确定 X 服务器所需的特定配置,但您可能必须确保您使用的服务器内置了虚拟帧缓冲区驱动程序。 虚拟帧缓冲区驱动程序是一种显示驱动程序,就像用于连接到 NVidia 或 ATI 显卡的驱动程序一样,只不过它的“输出”是包含像素的内存块,而不是 LCD 屏幕。
xwd 是标准 X 工具之一,可以创建 X 窗口转储。 可以在命令行上告诉 xwd 要转储哪个窗口。 它将时髦的“xwd”格式的流输出到标准输出。
NetPBM 实用程序是命令行工具的集合,可将一种图像格式转换为另一种图像格式。 它包括一个转换 xwdtoppm 的工具。 PPM 是一种非常基本的非压缩格式,是大多数 NetPBM 工具都能理解的中间格式。
cjpeg 是标准 JPEG 工具集合的一部分,如果您也有 NetPBM,则可能已安装。 cjpeg 可以获取 PPM 字节流并发出 JPEG 字节流。
通过 Unix 脚本和管道的魔力,您可以将这些实用程序连接在一起,以通过窗口启动应用程序,调用 xwd、xwdtoppm 和 cjpeg 将图像转储到文件中。
It sounds like you'll need to use the "virtual framebuffer" driver for the X.org server, combined with the xwd, NetPBM, and cjpeg utilities.
I'm not sure about the particular configuration you'll need for the X server, but you will likely have to make sure the server you're using has the virtual framebuffer driver built into to. The virtual framebuffer driver is a display driver just like one you'd use to connect to an NVidia or ATI video card, except it's "output" is a chunk of memory that contains the pixels, not an LCD screen.
xwd is one of the standard X tools, that can create a X Window Dump. xwd can be told on the command line which window to dump. It outputs a funky "xwd" formatted stream to standard out.
The NetPBM utilities are a collection of command line tools that convert one image format to another. It includes one that converts xwdtoppm. PPM is a very basic, non-compressed format that is the intermediate format understood by most of the NetPBM tools.
cjpeg is part of the standard JPEG tools collection, and is probably installed if you also have NetPBM. cjpeg can take a stream of PPM bytes and emit a stream of JPEG bytes.
Through the magic of Unix scripting and pipes, you can string these utilities together to fire up the app with the window, call xwd, xwdtoppm, and cjpeg to dump the image to a file.
您可以尝试运行 vncserver 来创建虚拟 X 窗口显示 - 不需要显卡。 请务必将 DISPLAY 变量设置为 vncserver 启动时打印的显示编号。 接下来,在创建的显示屏上启动您的应用程序(在 hte 背景中),并使用 xwd 和数据格式化程序或 gimp 命令将屏幕图像捕获为 jpeg。
顺便说一下,检查命令行程序创建的类似答案网站屏幕截图(在 Linux 上)。
You might try running vncserver to create a virtual X window display - no graphics card needed. Be sure to set your DISPLAY variable to the display number that gets printed when vncserver starts. Next, start your app on the created display (in hte background) and use xwd with data formatters or a gimp command to capture the screen image to jpeg.
By the way, check the similar answers for Command line program to create website screenshots (on Linux).