简体   繁体   English

使用 QPixmap 而不是 QImage?

[英]Use QPixmap instead of QImage?

I have an application where I copy some raw image data into a QImage directly:我有一个应用程序,我将一些原始图像数据直接复制到 QImage 中:

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稍后这个 QImage 是通过调用绘制的

painter.drawPixmap();

Unfortunately drawPixmap() cannot handle a QImage directly, so it first has to be converted:不幸的是 drawPixmap() 不能直接处理 QImage ,所以它首先必须被转换:

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?因此我的问题是:QPixmap 中是否有任何 function 允许像在 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.我的想法是从一开始就使用 QPixmap,将原始图像数据复制到 QPixmap object 中,然后直接使用它。

Thanks:-)谢谢:-)

First of all you won't need that loop to create the QImage.首先,您不需要该循环来创建 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.如果有任何特定原因使用 QPixmap(如QPixmap 缓存),您将别无选择,只能先将其转换为 QPixmap。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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