代码改变世界

QT在windows下实现截屏操作并保存为png图片

2014-05-06 11:35  江湖么名  阅读(851)  评论(0编辑  收藏  举报
QPixmap originalPixmap = QPixmap::grabWindow(QApplication::desktop()->winId());

 QString format = "png";
     QString initialPath = QDir::currentPath() + tr("/untitled.") + format;

     QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"),
                                initialPath,
                                tr("%1 Files (*.%2);;All Files (*)")
                                .arg(format.toUpper())
                                .arg(format));
     if (!fileName.isEmpty())
         originalPixmap.save(fileName, format.toAscii());