gpt4 book ai didi

c++ - 我可以重复使用 QPainter 吗?

转载 作者:行者123 更新时间:2023-11-28 02:28:07 25 4
gpt4 key购买 nike

渲染到位图,我必须创建一个 QPainter。如果我必须将多个区域渲染到多个位图,我该如何重置 QPainter?

QImage img1(scene1.sceneRect().size().toSize(), QImage::Format_ARGB32_Premultiplied);
img1.fill(Qt::color0);
QPainter painter1(&img1);
painter1.setRenderHint(QPainter::Antialiasing);
scene1.render(&painter1);
painter1.end();

QImage img2(scene2.sceneRect().size().toSize(), QImage::Format_ARGB32_Premultiplied);
img2.fill(Qt::color0);
QPainter painter2(&img2);
painter2.setRenderHint(QPainter::Antialiasing);
scene2.render(&painter2);
painter2.end();

如何重用 painter ?我是否通过为每个场景/图像创建一个新的 QPainter 来获得性能命中/更高的内存使用?

尝试

QImage img(scene1.sceneRect().size().toSize(), QImage::Format_ARGB32_Premultiplied);
img.fill(Qt::color0);
QPainter painter(&img);
painter.setRenderHint(QPainter::Antialiasing);
scene1.render(&painter);
painter.end();
img.save("img.png");

img = QImage(scene2.sceneRect().size().toSize(), QImage::Format_ARGB32_Premultiplied);
img.fill(Qt::color0);
painter = QPainter(&img);
painter.setRenderHint(QPainter::Antialiasing);
scene2.render(&painter);
painter.end();

我得到了这种类型的错误

error: 'QPainter& QPainter::operator=(const QPainter&)' is private

最佳答案

您可以使用以下语法重用您的QPainter:

QPainter painter;

painter.begin( &img1 );
...
painter.begin( &img2 );
...

但是您只能对一个QPaintDevice(在本例中为图像)使用一个QPainter

Read this.

关于c++ - 我可以重复使用 QPainter 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29833533/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com