QPainter性能如何提高? [英] How can QPainter performance be improved?

查看:577
本文介绍了QPainter性能如何提高?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大的显示屏(大约1000x2000像素),我正在做以下事情来将图像绘制到屏幕上:

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.

我绘制的画面越大,绘制的时间越长。我想pImage是memcpy'd,这是不同的。我怎样才能减少这种开销?我不想在这里扩大规模或任何东西。

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.

推荐答案

你正在绘制一个QImage。不要这样做,请尝试使用QPixmap。

You're painting a QImage. Don't do that, try with a QPixmap instead.

QImage文档 b
$ b

From the QImage documentation:


QImage是为I / O设计和优化的,像素访问和操作,而QPixmap的设计和优化,在屏幕上显示图像。

QImage is designed and optimized for I/O, and for direct pixel access and manipulation, while QPixmap is designed and optimized for showing images on screen."

取决于平台,获取QImage数据进入绘画所需的格式和位置,可能会非常昂贵。

Depending on the platform, getting the QImage data into the format and location needed for painting, can be extremely expensive.

PS:没有必要在堆上创建QImages,因为

P.S.: There is no need to create QImages on the heap, as


由于QImage类使用隐式数据共享,QImage对象可以按值传递。

QImage objects can be passed around by value since the QImage class uses implicit data sharing.

这篇关于QPainter性能如何提高?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆