Qt调整图像的最佳质量

Qt resize image with best quality

本文关键字:最佳 调整 图像 Qt      更新时间:2023-10-16

谁能帮我在qt中调整图像大小而不使图像像素化?这是我的代码。结果没有原来的质量好,谢谢。

QImage img(name);
QPixmap pixmap;
pixmap = pixmap.fromImage(img.scaled(width,height,Qt::IgnoreAspectRatio,Qt::FastTransformation));
QFile file(folder+"/"+name);
file.open(QIODevice::WriteOnly);
pixmap.save(&file, "jpeg",100);
file.close();

您必须将Qt::SmoothTransformation转换模式传递给scaled函数,如:

QImage img(name);
QPixmap pixmap;
pixmap = pixmap.fromImage(img.scaled(width,height,Qt::IgnoreAspectRatio,Qt::SmoothTransformation));
QFile file(folder+"/"+name);
file.open(QIODevice::WriteOnly);
pixmap.save(&file, "jpeg",100);
file.close();