0
votes

I have an application where I copy some raw image data into a QImage directly:

QImage* img = new QImage(desc.Width, desc.Height, QImage::Format_RGB32);
for (y = 0; y < img->height(); y++)
{
   memcpy(img->scanLine(y), &rawData[y * pRes->RowPitch], pRes->RowPitch);
}
return img;

Later this QImage is drawn via a call

painter.drawPixmap();

Unfortunately drawPixmap() cannot handle a QImage directly, so it first has to be converted:

m_bgImage = new QPixmap();
m_bgImage->convertFromImage(image);

Due to timing reasons I would like to drop this additional conversion step.

Thus my question: are there any function in QPixmap that allow direct image data manipulation right as in QImage?

My idea would be to start with a QPixmap from the very beginning, copy the raw image data into the QPixmap object and then use it directly.

Thanks :-)

1
Why did you start with QImage? Was there a particular reason? - vahancho
You can draw image instead of pixmap, QPainter::drawImage. - Kao
It's not unreleated, it's useless to create QImage/QPixmap pointers. And depending on your OS converting your QImage to QPixmap and vice versa is a no-op nowadays (also e.g. depending on the QImage format). Take a look into the Qt sources how it's implemented for your OS. - chehrlic
@chehrlic so you suggest to have a platform-dependent implementation while using a platform-independent toolkit like Qt? Dropping all the advantages such a platform-independent solution offers? Ahem...yes...never heard such a nonsense before... - Elmi

1 Answers

2
votes

First of all you won't need that loop to create the QImage. You can:

QImage* img = new QImage(&rawData, desc.Width, desc.Height, pRes->RowPitch * 4, QImage::Format_RGB32);

Then you can

painter.drawImage(QPointF(0,0),*img);

If there is any specific reason to use QPixmap (like QPixmap caching) you will have no other choice than convert it to QPixmap first.