【问题标题】:Qt resize image with best qualityQt 以最佳质量调整图像大小
【发布时间】:2014-05-04 08:28:32
【问题描述】:

谁能帮我在不使图像像素化的情况下调整 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 代替 Qt::FastTransformation 吗?

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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2014-02-17
    • 2021-02-15
    • 2011-06-16
    • 1970-01-01
    • 1970-01-01
    • 2010-12-10
    • 2013-02-15
    • 2011-01-24
    • 2020-08-20
    相关资源
    最近更新 更多