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

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());

你可能感兴趣的:(windows)