c++ - 使用 QPainter 绘制着色 QPixmap

标签 c++ windows qt

我有一个加载了 QPixmap 的单色透明 PNG,我想使用不同的颜色多次绘制这个像素图(例如,一次为绿色,另一次为黄色,等等)。这些 QPixmaps 通过 QPainter 在 QWidget 的 paintEvent 函数中渲染。

最佳答案

您可以将像素图转换为 qimage 并绘制您自己的颜色。

1- 使用QImage::fill(DesiredColor)

2- QPaintDevice 支持 QImage,所以使用 QPainter painter(&qImage);//8 位在绘画事件中不支持。

然后使用 QPixmap::fromImage(qImage);

用图像重新创建 QPixmap

关于c++ - 使用 QPainter 绘制着色 QPixmap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22739612/

相关文章:

c++ - 与 unique_ptr 混淆

c# - 如何从控制台应用程序绘制基于 DataTable 的图表?

c++ - 如何将 boost 库链接到我的项目?

c++ - Qt 5.3 QSystemTrayIcon 无法正常工作[Linux]

c++ - QVariant 无法区分 QDateTime 和 QString

c++ - memory_order_consume 和 memory_order_acquire 的区别

python - 你如何将 (char)B00000001 (c++) 翻译成 python 等价物?

c++ - 创建进程和0xc0000142错误

windows - 有没有办法做一个异步FindNextFile?

c++ - 为什么对一个 vector 进行多线程操作的速度很慢?