Quality of scaled Pixmaps
-
Hi,
the quality of a scaled png image seems to be very bad, especially if there is
text in the image. This is the case, even if the size of the original image is the same as the scaled image.The image is scaled in this way:
QPixmap image(path); int h = ui.picturePlaceholder->height(); int w = ui.picturePlaceholder->width(); QLabel *ui.image; ui.image->setPixmap(image.scaled(w, h, Qt::KeepAspectRatio));
I tried to optimize the resolution of the original image before scaling.
Is there a way to improve the quality of the image for the scaling or fitting process?
What could be responsible for the bad quality?Thanks for help.
-
@artwaw said in Quality of scaled Pixmaps:
Try
ui.image->setPixmap(image.scaled(w,h,Qt::KeepAspectRatio,Qt::SmoothTransformation));
Thanks, this a step in the correct direction. It improves lines and borders in the image..
The text is improved at some positions, at some other positions its worse.Is the png format the problem?
-
@TauCeti should not be, raster is raster and png compression should not affect (unlike certain jpg compression parameters). From my experience problem almost every time lies in the size/quality of the source image (I did render A5 pdf files into raster image, lot's of fun)
-
@JoeCFD said in Quality of scaled Pixmaps:
@TauCeti it is a problem. Use svg format which keeps the resolution of the image in scaling.
I will try this also. Can you help me with the correct way of implementing a svg? As I remember it can not be used with a QLabel.
-
@JoeCFD OP asked about bitmaps/rasters not vectors.
@TauCeti Details on SVG are here: https://doc.qt.io/qt-5/svgrendering.html
For that distorted bitmap of yours, are you sure you are not upscaling? If you enlarge bitmaps distortion is rather... inevitable.
-
@TauCeti said in Quality of scaled Pixmaps:
ui.image->setPixmap(image.scaled(w, h, Qt::KeepAspectRatio));
4th arguement to scaled function can be passed as Qt::SmoothTransformation
even if the size of the original image is the same as the scaled image.
get the original image size and check with placeholder size, @artwaw pointed out you might be doing image upscaling.