Qt resize image with best quality
Asked Answered
W

1

13

Can anyone help me resize an image in qt without making the image pixelated. Here's my code. the result is not as good as the original quality..thanks...

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();
Wreathe answered 26/3, 2014 at 5:46 Comment(2)
Do you shrink or extend the image? If you extend the image you will always have a "big" quality loss, since there is no more information for the new space than in the original image. Nevertheless every resize will be a loss in quality. There are quite a few algorithms for this all having different pros and cons.Whispering
Did you try using Qt::SmoothTransformation instead of Qt::FastTransformation?Millham
C
25

You have to pass Qt::SmoothTransformation transformation mode to the scaled function like:

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();
Crosse answered 26/3, 2014 at 6:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.