QPainter :: drawPixmap()看起来不好并且质量低劣? [英] QPainter::drawPixmap() doesn't look good and has low quality?

查看:1827
本文介绍了QPainter :: drawPixmap()看起来不好并且质量低劣?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用QPainter::drawPixmap()QWidget中绘制一个图标(.png) :

I'm trying to draw an icon(.png) inside a QWidget with QPainter::drawPixmap() :

QPixmap _source = "/.../.png";
painter.setRenderHint(QPainter::HighQualityAntialiasing);
painter.drawPixmap(rect(), _source);

但与(例如)QLabel相比,尺寸较小(在我的情况下为19 * 19),效果并不理想.

but in comparing to QLabel (for example) and in lower size (19*19 in my case) the result isn't perfect.

我该怎么办?

****编辑****

****Edit****

QLabel具有像素图@尺寸19 * 19:

QLabel with pixmap @ size 19*19:

通过SmoothPixmapTransform渲染类型,我的画@ 19 * 19尺寸:

My painting @ size 19*19 via SmoothPixmapTransform render type:

推荐答案

您设置了错误的渲染提示,您需要QPainter::SmoothPixmapTransform才能顺利调整大小.默认情况下,使用最近的邻居方法,该方法快速但质量很差并且像素化结果.

You are setting the wrong render hint, you need QPainter::SmoothPixmapTransform to get smooth resizing. By default the nearest neighbor method is used, which is fast but has very low quality and pixelates the result.

QPainter::HighQualityAntialiasing用于绘制线和填充路径等,即在光栅化几何图形时,它对绘制光栅图形没有影响.

QPainter::HighQualityAntialiasing is for when drawing lines and filling paths and such, i.e. when rasterizing geometry, it has no effect on drawing raster graphics.

似乎只有SmoothPixmapTransform可以做的事情很多,而当最终结果是如此之小时,它就不多了:

It seems there is only so much SmoothPixmapTransform can do, and when the end result is so tiny, it isn't much:

  QPainter p(this);
  QPixmap img("e://img.png");
  p.drawPixmap(QRect(50, 0, 50, 50), img);
  p.setRenderHint(QPainter::SmoothPixmapTransform);
  p.drawPixmap(QRect(0, 0, 50, 50), img);
  img = img.scaled(50, 50, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
  p.drawPixmap(100, 0, img);

此代码产生以下结果:

第二张和第三张图像之间几乎没有任何区别,手动将源图像缩放到所需的尺寸并绘制它可以产生最佳效果.这当然是不对的,希望从SmoothTransformation获得相同的结果,但是由于某种原因,它的缩放效果不如QPixmapscale()方法.

There is barely any difference between the second and third image, manually scaling the source image to the desired dimensions and drawing it produces the best result. This is certainly not right, it is expected from SmoothTransformation to produce the same result, but for some reason its scaling is inferior to the scale() method of QPixmap.

这篇关于QPainter :: drawPixmap()看起来不好并且质量低劣?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆