c++ - How to Reduce the noisy While Scale a Image/Picture with Qt -
i use code like:
void mylabel::paintevent(qpaintevent *event){ qpainter painters(this); /*对img进行平滑缩放*/ int image_width,image_height; image_width = width(); image_height = height(); qimage result = img.scaled(image_width<<2, image_height<<2).scaled(image_width, image_height,qt::ignoreaspectratio,qt::smoothtransformation ); painters.drawpixmap(0,0,image_width,image_height,qpixmap::fromimage(img)); } i want scale image size want, when scale non equal proportion , terrible things happened ,noisy huge ,and image/picture this:

and want know how way scale image/picture instead:

i suspect because call qimage::scaled() twice, first upscale 4× desired size , second actual desired size. first call uses default value transformation mode (which qt::fasttransformation). you're combining non-smooth , smooth transformation. note first transformation should unnecessary anyway. scale desired size immediately, using qt::smoothtransformation.
qimage result = img.scaled(image_width, image_height, qt::ignoreaspectratio, qt::smoothtransformation); edit: noticed else. @ drawpixmap line:
painters.drawpixmap(0,0,image_width,image_height,qpixmap::fromimage(img)); you're drawing original img when meant draw result:
painters.drawpixmap(0,0,image_width,image_height,qpixmap::fromimage(result));
Comments
Post a Comment