9

I have the following UI, where the sonogram (freq+time sound representation) is shown. So the image is not loaded from somewhere, it is drawn by QPainter while reading WAV file.

The UI

My current implementation is a single huge QImage object, where the image is drawn. And on paintEvent(), I draw part of the large QImage on the widget:

QPainter painter(this);
// (int, int, QImage*, int, int)
painter.drawImage(0, 0, *m_sonogram, 0, m_offset);

But, as i know, the QPixmap is optimized for displaying pixmaps on the screen, so should I convert the QImage to a QPixmap after the drawing of the sonogram is done?

Also, is it worth to keep large image as some kind of a linked list of separate QPixmap objects of smaller size and make paintEvent() smarter to operate on a list of smaller objects to avoid Qt's auto-cutting procedures and so on?

When my QImage is large enough, each paintEvent() consuming a lot of CPU.

All kinds of advices are welcome :)

4

1 回答 1

1

QPixmap是的,在我有限的 Qt 应用程序开发经验中,如果您有一个静态图像(或不经常更新的图像),那么(出于性能目的)从它创建一个并保留它以QPainter::drawPixmap在您的处理程序中使用是非常值得的paintEvent

但是,我从未尝试过使用大于 4Kx4K 的图像来执行此操作,因此,当您开始对图形内存施加压力时,它是否适用于您的巨大图像或严重崩溃,我不能说。在考虑添加复杂的平铺系统之前,我肯定会尝试一下。

于 2012-02-28T23:07:59.903 回答