Qt - load bmp565 into QPixmap

1.8k views Asked by At

I am working on application which needs to load bmp 16bit(5-6-5) images to QPixmap. Is there any way in Qt of doing this directly like for 24bit bmp's?

I tried to convert all images to 24bit version and there were no problems with loading them. Unfortunately I really need to work with 16bit.

I tried also the following code, but without success. However I could load 16bit (1-5-5-5) version of my bmp.

QImage img = QImage(300, 300, QImage::Format_RGB16);
img.loadFromData(imgArray);
ui->test->setPixmap(QPixmap::fromImage(img));
1

There are 1 answers

3
Andrzej Pronobis On BEST ANSWER

It seems to work pretty well for me using the QImage constructor:

QImage::QImage(const QString & fileName, const char * format = 0)

Basically, the use would be:

QImage img = QImage("filename.bmp")

and the RGB16 format should be picked up by the constructor on its own from the file header.

EDIT:

The file you posted seems to be using a header type that is not supported by Qt. It is an undocumented header with size 56 called BITMAPV3INFOHEADER, which Wikipedia explains as:

Not officially documented, but this documentation was posted Adobe's forums, by an employee of Adobe with a statement that the standard was at one point in the past included in official MS documentation https://forums.adobe.com/message/3272950#3272950

It seems to be a quite special header type that is not supported by many libraries. However, gimp or ImageMagic can load it and convert it, so I suggest that you converted your files to another BMP file with RGB565 encoding that uses a more standard header. Then, the above code will work for you.