Tricks
To capture the rendered image from the virtual display (since the program itself doesn't save it), you can use a screen capture tool that works with virtual displays like Xvfb. Here's how you can achieve this:
Steps to Capture the Image from the Virtual Display
-
Install
xwd
(X Window Dump):xwd
is a utility that captures the contents of an X Window display (including virtual displays created by Xvfb).- Install
x11-apps
package, which includesxwd
:sudo apt-get install x11-apps # Debian/Ubuntu-based systems sudo yum install xorg-x11-apps # RHEL/CentOS-based systems
-
Run Your Program with Xvfb:
After setting up Xvfb as mentioned before, run the program in the virtual display:Xvfb :99 -screen 0 1024x768x24 & export DISPLAY=:99 ./your_program
-
Capture the Screen Using
xwd
:
Usexwd
to capture the contents of the virtual display as an image:xwd -root -display :99 -out screenshot.xwd
This will capture the entire virtual display and save it as a file named
screenshot.xwd
. -
Convert the Captured Image (Optional):
The output format (.xwd
) might not be suitable for direct use. You can convert it to a more common format (like PNG or JPEG) using tools such as ImageMagick:- Install ImageMagick:
sudo apt-get install imagemagick
- Convert
.xwd
to.png
:convert screenshot.xwd screenshot.png
- Install ImageMagick:
-
View the Image:
- Once the image is converted to a more common format like PNG, you can transfer the file back to your Mac and view it using any standard image viewer.
- To transfer the file:
scp user@yourserver.com:/path/to/screenshot.png /local/path/
Full Process Example:
# Start Xvfb
Xvfb :99 -screen 0 1024x768x24 &
export DISPLAY=:99
# Run your program
./your_program &
# Capture the virtual display
xwd -root -display :99 -out screenshot.xwd
# Convert to PNG format
convert screenshot.xwd screenshot.png
# (Optional) Transfer to local Mac
scp user@yourserver.com:/path/to/screenshot.png /local/path/
This process allows you to render the image in the virtual display, capture it, and then convert and view it locally.
Would this workflow work for you?
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人