Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt resize image with best quality

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();
like image 989
James Seva Avatar asked Mar 26 '14 05:03

James Seva


People also ask

How can I resize an image without losing quality?

One way to do this is to use a program like Photoshop. With Photoshop, you can resize an image without losing quality by using the "Image Size" dialog box. In the "Image Size" dialog box, you can change the width and height of the image. You can also change the resolution.

How do I resize a PNG without losing quality?

Open your file and click the Image tab in the upper tool panel, then select Image Size. Make sure that the link icon is “on” to scale proportionately. Change the width and height as needed. Click OK and save with a new filename to preserve your original image.

Does resizing an image reduce quality?

Frequently asked questions: Does resizing an image affect its quality? It definitely can! Typically, making an image smaller will not impact the quality, but an image can suffer quality loss when scaled beyond its original size.


1 Answers

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();
like image 114
Nejat Avatar answered Nov 16 '22 03:11

Nejat