I had same needs and never succeed with QImage::loadFromData since you need to write the header I presume.


Just create a QImage with the right pixel size, with the format QImage::Format_Indexed8
Then get acces buffer data in read/write with scanline, and use memset to copy from your buffer into the image buffer in a loop.

You can set color values in your color table for each different pixel with QImage::setColor . Each pixel value of your source buffer is the index and you need to convert your colors into QRgb. Empty entries will be not used.

There is another way to copy the whole buffer in one instruction with QImage::bits but since buffer inside the image is 32bits aligned, you will get an offset and unexpected result.