Download QPixmap from QByteArray in Qt?

I have a byte array with the contents of the image (in png / bmp or in some other format).

How to upload it to QPixmap?

+6
source share
3 answers
bool QPixmap::loadFromData ( const QByteArray & data, const char * format = 0, Qt::ImageConversionFlags flags = Qt::AutoColor ) 

The format here is a string literal similar to "PNG" or something similar

 QPixmap p; QByteArray pData; // fill array with image if(p.loadFromData(pData,"PNG")) { // do something with pixmap } 
+13
source

You should use the following: 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 ) ); 
+6
source

Use this constructor:

 QImage ( const uchar * data, int width, int height, Format format ) 

More details ... After that, you can use QPixmap.convertFromImage() to create the pixmap.

0
source

Source: https://habr.com/ru/post/893564/


All Articles