1

I'm sending a QImage (as a byte array) from my C++ qt app through a socket to a python process. I want to restore the RGB channels to a numpy array representing the image. However, I couldn't find any documentation on how the Qimage is stored or sent when writing it to a bytearray. I would prefer not using Qt on the python side.

The code for sending the raw bytes is already working, I'm struggling with understanding the composition of the raw data back to the RGB channels. The image is BMP, with QImage::Format_RGB32, using Qt 5.7, python 2.7.12.

So far I'm getting that the amount of bytes is 3*width*height so I assume it is a byte for each of R,G,B, but there are 54 more bytes that I don't know what they rerpresnt. Also, If the image is RGB32, shouldn't it be 4 bytes per pixel? I don't have an alpha channel, so it's weird.

JLev
  • 705
  • 1
  • 9
  • 30
  • 1
    That would be the [header](https://en.wikipedia.org/wiki/BMP_file_format#Bitmap_file_header), which contains information like width, height, bitdepth, etc. – Reti43 Oct 23 '17 at 08:11
  • @Reti43 Thanks :) using your link and http://avisynth.nl/index.php/RGB24 I've managed to do it. – JLev Oct 23 '17 at 10:31
  • If QImage sends you the raw data of a bitmap image, call it, `stream`, you can let PIL load the image with `Image.open(io.BytesIO(stream))`. If you have used a different approach, consider writing an answer so that future readers will benefit from it. – Reti43 Oct 23 '17 at 10:37
  • actually what you wrote now was exactly what I needed (I did something messier that worked, but this is much better). Thanks – JLev Oct 23 '17 at 10:41
  • 1
    Unfortunately, it's something I should have mentioned earlier to save you the time. For some reason I lapsed and I referred to your 54 missing bytes, forgetting that ultimately you were trying to load the image. – Reti43 Oct 23 '17 at 10:49

0 Answers0