简体   繁体   中英

Use QPixmap instead of QImage?

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:-)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM