-1

The c++ client has QImage which must be sent via a tcp socket to the python server and saved in jpeg there. The server does not use qt. Could you explain how to do this correctly? How do I write data from QImage to the socket and how do I read it in python for later saving? QImage is a little unclear to me.

RemQ
  • 1

1 Answers1

0

One option could be converting QIMage to base64 data and you can de-serialize this later in python side:

in c++ side

QByteArray byteArray;
QBuffer buffer(&byteArray);
image.save(&buffer, "PNG"); // writes the image in PNG format inside the buffer
QString iconBase64 = QString::fromLatin1(byteArray.toBase64().data());

in python side:

# For both Python 2.7 and Python 3.x
import base64
with open("imageToSave.png", "wb") as fh:
    fh.write(base64.decodebytes(img_data))
Akhil Thayyil
  • 9,263
  • 6
  • 34
  • 48