Qt以最佳质量调整图像大小

时间:2014-03-26 05:46:33

标签: c++ qt image-resizing qimage qpixmap

任何人都可以帮我调整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();

1 个答案:

答案 0 :(得分:15)

您必须将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();