1

I can send and get QPixmap by QByteArray:

QPixmap pixmap1;
QByteArray rawPixels;
QBuffer buffer(&rawPixels);
buffer.open(QIODevice::WriteOnly);
pixmap1.save(&buffer, "PNG");

QPixmap pixmap2;
pixmap2.loadFromData(rawPixels,"PNG");

but I have to use std::vector<unsigned char> to send my pixmap:

std::vector<unsigned char> vector;
int size = rawPixels.size();
char* temp = (char*) rawPixels.constData();
vector.resize(size);
for(int index = 0; index < size; index++)
{
    vector.push_back(temp[index]);
}

Is there an easy way to get a QPixmap from a std::vector<unsigned char>?

4

1 回答 1

1

您可以将loadFromData与 unsigned char 数组一起使用

bool QPixmap::loadFromData ( const uchar * data, uint len, const char * format = 0,
                             Qt::ImageConversionFlags flags = Qt::AutoColor )

使用vector.data()获取连续的基础数据。

于 2014-10-16T08:55:56.233 回答