公告
财富商城
积分规则
提问
发文
2019-06-19 15:56发布
成全新的幸福
I have a byte array with the contents of an image (in png/bmp or some other format).
How can I load it into a QPixmap?
bool QPixmap::loadFromData ( const QByteArray & data, const char * format = 0, Qt::ImageConversionFlags flags = Qt::AutoColor )
Format here is string literal like "PNG" or something similar
"PNG"
QPixmap p; QByteArray pData; // fill array with image if(p.loadFromData(pData,"PNG")) { // do something with pixmap }
Use this constructor:
QImage ( const uchar * data, int width, int height, Format format )
Here is more info. After that, you can use QPixmap.convertFromImage() to create a pixmap.
QPixmap.convertFromImage()
You should use the folowing, where your bytes are in the imageData variable in the format specified by the last parameter:
QPixmap pixmap = QPixmap::fromImage( QImage( (unsigned char *) imageData, image_width, image_height, QImage::Format_RGB888 ) );
最多设置5个标签!
Format here is string literal like
"PNG"
or something similarUse this constructor:
Here is more info. After that, you can use
QPixmap.convertFromImage()
to create a pixmap.You should use the folowing, where your bytes are in the imageData variable in the format specified by the last parameter: