简体   繁体   English

Linux:启动窗口,捕获屏幕

[英]Linux: launch window, capture screen

I need to write a Red Hat Linux command line tool that launches a window and captures its appearance to disk as a JPEG. 我需要编写一个Red Hat Linux命令行工具,该工具会启动一个窗口并将其外观以JPEG格式捕获到磁盘上。

Typically the target machines don't have graphics cards, but we can install any software components (eg, X). 通常,目标计算机没有图形卡,但是我们可以安装任何软件组件(例如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? 如果我要使用GTK +之类的工具来创建此工具,缺少视频卡会不会妨碍其执行?

I saw scrot , but it doesn't appear to support capturing a specific window without user interaction. 我看到了scrot ,但似乎没有用户交互就不支持捕获特定窗口。

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. 听起来您需要将X.org服务器的“ 虚拟帧缓冲”驱动程序与xwdNetPBMcjpeg实用程序结合使用。

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. 我不确定X服务器所需的特定配置,但是您可能必须确保所使用的服务器具有内置的虚拟帧缓冲驱动程序。 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. 虚拟帧缓冲驱动程序是一种显示驱动程序,就像您用来连接到NVidia或ATI视频卡的驱动程序一样,不同之处在于它的“输出”是一块包含像素的内存,而不是LCD屏幕。

xwd is one of the standard X tools, that can create a X Window Dump. xwd是标准的X工具之一,可以创建X Window Dump。 xwd can be told on the command line which window to dump. 可以在命令行上告诉xwd要转储哪个窗口。 It outputs a funky "xwd" formatted stream to standard out. 它输出一个时髦的“ xwd”格式的流,以标准输出。

The NetPBM utilities are a collection of command line tools that convert one image format to another. NetPBM实用程序是命令行工具的集合,这些工具可将一种图像格式转换为另一种图像格式。 It includes one that converts xwdtoppm. 它包括将xwd转换为ppm的一种。 PPM is a very basic, non-compressed format that is the intermediate format understood by most of the NetPBM tools. PPM是一种非常基本的非压缩格式,是大多数NetPBM工具可以理解的中间格式。

cjpeg is part of the standard JPEG tools collection, and is probably installed if you also have NetPBM. cjpeg是标准JPEG工具集合的一部分,如果您还具有NetPBM,则可​​能已安装。 cjpeg can take a stream of PPM bytes and emit a stream of JPEG bytes. cjpeg可以获取PPM字节流,并发出JPEG字节流。

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. 通过Unix脚本和管道的魔力,您可以将这些实用程序串在一起,用窗口启动应用程序,调用xwd,xwdtoppm和cjpeg将映像转储到文件中。

You might try running vncserver to create a virtual X window display - no graphics card needed. 您可以尝试运行vncserver创建虚拟X窗口显示-无需图形卡。 Be sure to set your DISPLAY variable to the display number that gets printed when vncserver starts. 确保将DISPLAY变量设置为vncserver启动时打印的显示编号。 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. 接下来,在创建的显示器上(在后台)启动您的应用程序,并将xwd与数据格式化程序或gimp命令配合使用,以将屏幕图像捕获为jpeg。

By the way, check the similar answers for Command line program to create website screenshots (on Linux) . 顺便说一句,检查命令行程序的类似答案以创建网站屏幕截图(在Linux上)

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

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