Intense drawing with QT

Started by
9 comments, last by Dospro 12 years, 9 months ago

[quote name='Dospro' timestamp='1311621712' post='4840142']
Ok. but again, With QPainter i have to set the pen for each individual pixel which is not quite efficient. If i have a resolution of 640*480 with 32 bpp each frame, that would be thousands of pen-sets to draw all the pixel for each frame(consider i want to get as far as 60 fps).

Do i really have to use QPainter or is another way?
Thanks for the help


Re-read this line:

A) If you are painting each individual pixel yourself, use QImage, and draw it with QPainter.[/quote]

That is to say, create a QImage, and fill the pixels using setPixel().
Alternatively, operate on raw data, then when finished, pass that raw data to a new QImage using this constructor.

If you draw your data more often then the data changes, you might try converting the QImage to a QPixmap using QPixmap::fromImage(), and keeping that QPixmap around until the next time you change your data. But profile it to see if it actually speeds anything up, or just slows it down.

Think of it like this: QImage is a buffer of pixels that QPainter can then draw onto your QWidget. You can either manipulate the buffer through QImage, or you can create your own buffer and manipulate that directly, and then just convert it to a QImage when finished.
Also, if you want extra drawing speed, you can convert the QImage to a QPixmap, but the actual conversion itself may negate any speed benefits you gain, so you have to profile it to see if it actually helps or not.

QPixmap is optimized for really fast drawing. QImage is optimized for image manipulation. QBitmap is only for binary masks, so ignore it. QPicture is for a program like MSPaint where someone is drawing a picture, so you can ignore that to.

Read this (from the Qt documentation):
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.[/quote]

But both QImage and QPixmap image you'll have to then use QPainter to actually draw, once you are done editing the pixels. QPainter::drawImage(), or QPainter::drawPixmap().
[/quote]

Ok. Now i understand. That helped a lot. And it actually works the way i want it now.
I have to see if it is as efficient as i expect yet.
Anyway. For now. Thankyou very much for all your help.

This topic is closed to new replies.

Advertisement