简体   繁体   English

使用QPainter绘制着色的QPixmap

[英]Drawing a Tinted QPixmap using QPainter

I have a single-color transparent PNG loaded with a QPixmap, I want to draw this pixmap multiple times using different colors (eg once green, another yellow, etc). 我有一个装有QPixmap的单色透明PNG,我想使用不同的颜色(例如一次绿色,另一种黄色等)多次绘制此像素图。 These QPixmaps are rendered through QPainter in the paintEvent function of a QWidget. 这些QPixmap通过QWidget的paintEvent函数中的QPainter呈现。

you can convert the pixmap into qimage and paint your own color . 您可以将像素图转换为qimage并绘制自己的颜色。

1- Use QImage::fill(DesiredColor) 1-使用QImage :: fill(DesiredColor)

2- QPaintDevice supports QImage so use QPainter painter(&qImage); 2- QPaintDevice支持QImage,因此请使用QPainter painter(&qImage); // 8 bit will not support in paint event . // 8位在绘画事件中不支持。

then recreate QPixmap with image using QPixmap::fromImage(qImage); 然后使用QPixmap :: fromImage(qImage);用图像重新创建QPixmap

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM