QT软件开发: 截取全屏、指定位置、当前窗口保存图片
【摘要】
一、环境介绍
QT : 5.12.6
操作系统: win10 x64
编译器: MinGW32
二、示例代码
头文件
#include <QScreen>#include <QTimer>connect(&timer, SIGNAL(timeout()), this, SLOT(update(...
一、环境介绍
QT : 5.12.6
操作系统: win10 x64
编译器: MinGW32
二、示例代码
头文件
#include <QScreen>
#include <QTimer>
connect(&timer, SIGNAL(timeout()), this, SLOT(update()));
timer.start(50);
2.1 截取全屏保存为图片
void Form::update()
{
static int cnt=0;
QScreen *screen = QGuiApplication::primaryScreen();
//截取当前桌面全屏画面
screen->grabWindow(0).save(QString("%1.jpg").arg(cnt++));
}
2.2 截取窗口指定位置保存图片
void Form::update()
{
static int cnt=0;
QScreen *screen = QGuiApplication::primaryScreen();
QRect rect;
rect.setX(this->mapToGlobal(this->pos()).x());
rect.setY(this->mapToGlobal(this->pos()).y());
rect.setWidth(this->width());
rect.setHeight(this->height());
screen->grabWindow(0,rect.x(),rect.y(),rect.width(),rect.height()).save(QString("%1.jpg").arg(cnt++));//截取当前桌面
}
2.3 截取当前窗口保存为图片
void Form::update()
{
//截取当前窗口画面.---不能透过窗口截后面
this->grab().save(QString("%1.jpg").arg(cnt++));
}
文章来源: xiaolong.blog.csdn.net,作者:DS小龙哥,版权归原作者所有,如需转载,请联系作者。
原文链接:xiaolong.blog.csdn.net/article/details/119730896
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)