c ++客户端具有QImage,必须通过tcp套接字将其发送到python服务器,并保存在jpeg中。服务器不使用qt。您能解释一下如何正确执行此操作吗?如何将数据从QImage写入套接字,以及如何在python中读取数据以便以后保存?QImage对我来说还不太清楚。
[一个选项可能是将QIMage
转换为base64
数据,您可以稍后在python方面对此反序列化:
在c ++方面
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());
在python端:
# For both Python 2.7 and Python 3.x
import base64
with open("imageToSave.png", "wb") as fh:
fh.write(base64.decodebytes(img_data))