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.
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.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