像素图屏幕截图转换为低质量

Pixmap screenshot convert to low-quality

我正在使用 qt creator 创建示例远程协助 我的项目有两部分服务器和客户端 客户端截取屏幕截图并将其发送到服务器,但屏幕截图图片质量太高而且尺寸太大,从局域网或互联网协议发送它不是个好主意 我需要调整图像大小或将其转换为低质量,以便几乎可以识别

这是我的截图代码

 void MainWindow::shootScreen()
 {
 originalPixmap = QPixmap(); // clear image for low memory situations
                             // on embedded devices.
 originalPixmap = QGuiApplication::primaryScreen()->grabWindow(0);

 //emit getScreen(originalPixmap);

 updateScreenshotLabel();


 }

 void MainWindow::updateScreenshotLabel()
 {
 this->ui->label_2->setPixmap(originalPixmap.scaled(this->ui->label_2-    >size(),
                                                  Qt::KeepAspectRatio,
                                                  Qt::SmoothTransformation));
 }

看来您知道如何更改图片大小,为什么这还不够?

就这样:

QPixmap smallPixmap = originalPixmap.scaled( QSize( originalPixmap.size().x()/4, originalPixmap.size().y()/4 ), Qt::KeepAspectRatio,                                                   Qt::SmoothTransformation );

并发送 smallPixmap 而不是 originalPixmap

您还可以(应该)使用 QImageWriter 压缩图像,这将允许您创建一个以 jpeg 格式压缩的图像,这也应该减少内存使用量。

Check this,看起来他们在做你想做的事。