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

Pixmap screenshot convert to low-quality

本文关键字:低质量 转换 屏幕截图 像素      更新时间:2023-10-16

我正在使用Qt Creator创建示例远程协助我的项目有 2 部分服务器和客户端客户端截取屏幕截图并将其发送到服务器,但屏幕截图图片必须具有很高的质量,并且占用太多大小,从局域网或Internet协议发送它不是好主意我需要调整图像大小或将其转换为低质量,以便几乎可以识别

这是我的屏幕截图代码

 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格式压缩的图像,这也应该减少内存使用量。

检查一下,看起来他们正在做你想做的事情。