How to keep QPixamp quality in QPainter::drawPixmap when QPainter::scale(x,y) is used?

I am using QWidget and its paintEvent.
Im using QPainter::scale(zoom,zoom) to scale background images on the widget.
Then I want to paint some foreground icons and keep their size the same all the time while preserving quality.

The problem is that even though the QPixamp is kept the same size, its quality decrades.
The bigger the “zoom” the bigger the loss in quality.

Minimal code example:

void myPainter::paintEvent(QPaintEvent *)
{
 QPainter p(this);
 p.scale(myZoom,myZoom)
 .
 .
 .
 double tagSize = t->icon_->height() / zoom;
 QPoint tagpoint = rect().center();
 p.drawPixmap(tagpoint, t->icon_->scaledToHeight(tagSize,Qt::SmoothTransformation));
}

I Used drawPixamp with scaled QPixmap.
I expected for the QPixamp quality to not decrade but stay the same.

EDIT:(a partial solution)
To keep the pixmap quality it was possible to
unzoom,draw,zoom to keep the image quality good and image samesize without resizing.

p.scale(1/zoom,1/zoom);
p.drawPixmap(tagpoint * zoom, *t->icon_);
p.scale(zoom,zoom);

This forced new calculation to the tag point the keep the position same, but it seems to work after calculating the position and taking the zoom to account in there.

0

The quality “degrades” because you’re scaling the pixmap down.

It’s like scaling a 100×100 image to 50×50 and then zooming it by a 2x ratio: the degradation is obvious because by scaling the image you lose the original contents, especially when scaling down.

Remember that a pixmap is a map of pixels (pix-map). Every scaling will always potentially result in a loss of contents, both when zooming in and out, with the exception of scaling up with integer factors and no scaling filter is applied.

Consider this canonical test image as a source, at 512×512:

Then scale it down by half the size:

Then this is how it would be painted with a “zoom in” factor of 2:

The “degradation” is caused by the fact that the transform applied on the painter can only work with the data it is provided: in this specific case, the reduced map of pixels of the scaled down image. You cannot get the “non-degraded” image, because that data does not exist in the scaled pixmap.

The only safe way to achieve an appropriate result without quality loss, then, is not by scaling the image, but to always draw the source with the appropriate transformation.

You can do it as you suggested in your question, or eventually by using the QPainter states.

p.save();
p.resetTransform();
// or, alternatively, p.scale(1/zoom, 1/zoom) as above
p.drawPixmap(tagpoint * zoom, *t->icon_);
p.restore();

The result would be identical to your proposal.

Note that saving the painter state may be slightly less efficient than just “unscale+paint+rescale” (as it saves its full state, including the current pen, brush, etc., which are obviously unnecessary in this specific case), but in some situations it is more effective, as having stacks of QPainter states may simplify code writing/readability/debugging.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật