您的位置:首页 > 编程语言 > Qt开发

[转]屏幕截屏原来是如此的简单

2017-11-29 09:46 218 查看
Qt的窗口框架

包括整个窗口:x(), y(), frameGeometry(), pos(), and move(). 提供这个几个函数,通过这个几个我们就可以方便的操作整个窗口的位置以实现截图啦。 
不包含窗口框(其实就一个标题栏)的:geometry(), width(), height(), rect(), and size().,通过这个几个函数我们就可以操作窗口的的Client 区域了。

QString fileName;
QPixmap pix, bmp;
pix =bmp.grabWindow(this->winId(),0,0,frameGeometry().width(),frameGeometry().height());
fileName= QDateTime::currentDateTime().toString("yyyy-MM-ddHH-mm-ss")  + ".bmp";//通过时间命名文件
if (pix.isNull())
{
QMessageBox::information(this, "Error", "截屏失败 !", QMessageBox::Ok);
}
else
{
if(!pix.save(fileName,"BMP"))
{
QMessageBox::information(this, "Right", "保存错误 !", QMessageBox::Ok);

}
else
{
QMessageBox::information(this, "Grab", "保存成功!",QMessageBox::Ok);
}
}


static QPixmap grabWindow(WId, int x=0, int y=0, int w=-1, int h=-1);
static QPixmap grabWidget(QObject *widget, const QRect &rect);
static inline QPixmap grabWidget(QObject *widget, int x=0, int y=0, int w=-1, int h=-1) //QRect myarea = ui.centralWidget;
{ return grabWidget(widget, QRect(x, y, w, h)); } //QRect(myarea)




Qt之对应用实现截屏并保存

      2 利用QT实现截屏的四种方法   *****
        
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  qt