如何提高 QPainter 的性能?
我有一个大显示器(大约 1000x2000 像素),我正在执行以下操作来将图像绘制到屏幕上:
QImage *pImage = GetImage(); // from wherever
QPainter painter(this);
painter.drawImage((0,0), *pImage); // this line takes over 100ms to complete.
我绘制的屏幕越大,绘制所需的时间就越长。我猜 pImage 正在被 memcpy'd,这就是区别。我怎样才能减少这种开销?我并不是想扩大规模或做任何事情。
谢谢。
I have a large display (about 1000x2000 pixels) and I'm doing the following to draw images to the screen:
QImage *pImage = GetImage(); // from wherever
QPainter painter(this);
painter.drawImage((0,0), *pImage); // this line takes over 100ms to complete.
The larger the screen is that I'm drawing to, the longer this paint takes. I guess the pImage is being memcpy'd and that's the difference. How can I reduce this overhead? I'm not trying to scale or anything here.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在绘制 QImage。不要这样做,尝试使用 QPixmap 代替。
来自 QImage 文档:
根据平台的不同,将 QImage 数据转换为绘画所需的格式和位置,可以 PS:不需要
在堆上创建 QImage,因为
You're painting a QImage. Don't do that, try with a QPixmap instead.
From the QImage documentation:
Depending on the platform, getting the QImage data into the format and location needed for painting, can be extremely expensive.
P.S.: There is no need to create QImages on the heap, as
您可以进行的一项简单改进是仅绘制需要更新的区域(如果可以的话)。
QPaintEvent
包含更改区域的矩形,并且QPainter::drawImage
具有重载那可以取矩形作为要绘制的部分。您还可以查看
ImageConversionFlags
更快的选项。One simple improvement you can make is to draw only the area that needs updated (if you can). The
QPaintEvent
contains a rect for the changed area, and theQPainter::drawImage
has overloads that can take rects for the portion to draw.You might also look at the
ImageConversionFlags
options for faster options.