PDA

View Full Version : Scaling QImage ( zooming ) and drawing slowes down the performance



sanjayshelke
7th May 2009, 10:34
Hi all,

I am developing small application which can edit image.That is it has Zoom and Erase functionality.

I am facing performance issue when i zoom the image and starts erasing it.

Zoom functionality is implemented by scaled() API of QImage and erase functionality is implemented by drawing on the scaled image with CompositionMode set to QPainter::CompositionMode_Clear.

How MSPAINT application does the same task smoothley.

Is there any way to improve the performance?

Thanks in advance

Regards,
~Sanjay

wysota
7th May 2009, 13:19
We'd have to see the exact code. I'm assuming you are converting between QImage and QPixmap all the time and this is slow.

sanjayshelke
7th May 2009, 14:08
Very true.

I am converting it from QPixmap to QImage.And then erased image using QPainter.
After done erasing converting to QPixmap again.

like this :


QImage imgPixmap(m_imgViewer->pixmap()->toImage());

QPainter painter(&imgPixmap);
painter.setCompositionMode(QPainter::CompositionMo de_Clear);
QPen pen;
pen.setCapStyle(Qt::RoundCap);
pen.setWidth(m_nEraserSize);
painter.setPen(pen);
painter.drawPoint(ptPos);
painter.end();

m_imgViewer->setPixmap(QPixmap::fromImage(imgPixmap)); // show the image
m_imgViewer->setMinimumSize(m_imgViewer->pixmap()->size());


Note : m_imgViewer is a QLabel.

Any idea how to do that.

Regards,
~Sanjay

wysota
7th May 2009, 15:25
How about having two pixmaps - one is the base image and the other is a mask that you will apply to the image when saving it. Then you don't have to convert the base pixmap, just operate on the upper "layer".

A simpler solution is to paint directly on the pixmap, you don't have to convert it to QImage before doing so.

sanjayshelke
8th May 2009, 13:04
Very sorry.
I am late to reply.
yes i tried painting directly on QPixmap and it works.

Thank you.


regards,
~Sanjay