嵌入式Linux系统下的 QT 截图程序
- 前言
- 环境配置
- QT程序源码
- 效果
前言
程序可以截取整个屏幕
环境配置
Linux终端运行QT程序,环境变量配置
export QT_EGLFS_IMX6_NO_FB_MULTI_BUFFER=1# 嵌入式FrameBuffer模式
export QT_QPA_PLATFORM=linuxfb:fb=/dev/fb0 # 或使用EGLFS(需要GPU支持)
export QT_QPA_PLATFORM=eglfs
QT程序源码
#include <QCoreApplication>
#include <QGuiApplication>
#include <QScreen>
#include <qdatetime.h>
#include <QPixmap>
#include <QDebug>
#include <QCoreApplication>
#include <QApplication>int main(int argc, char *argv[])
{qDebug()<<"------------start-------------";QGuiApplication app(argc, argv);// 获取主屏幕对象QScreen *primaryScreen = QGuiApplication::primaryScreen();if (!primaryScreen) {qDebug()<<"------------no primaryScreen-------------";return -1;}qDebug()<<"------------截取整个屏幕(root window)-------------";QPixmap screenshot = primaryScreen->grabWindow(0);qDebug()<<"------------生成带时间戳的文件名-------------";QString filename = QDateTime::currentDateTime().toString("'screenshot_'yyyyMMdd-hhmmss'.png'");qDebug()<<"filename ="<<filename;// 保存为PNG格式screenshot.save(filename, "PNG");return app.exec();
}