简体   繁体   English

的std ::矢量 <unsigned char> 到QPixmap

[英]std::vector<unsigned char> to QPixmap

I can send and get QPixmap by QByteArray : 我可以通过QByteArray发送和获取QPixmap

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>发送我的像素图:

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> ? 有没有一种简单的方法可以从std::vector<unsigned char>获取QPixmap

You can use loadFromData with an unsigned char array 您可以将loadFromData与无符号char数组一起使用

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

Use vector.data() to get the contiguous underlying data. 使用vector.data()获取连续的基础数据。

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

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