[英]Send QImage from c++ client to python server
The c++ client has QImage which must be sent via a tcp socket to the python server and saved in jpeg there. c++ 客户端具有 QImage,它必须通过 tcp 套接字发送到 python 服务器并保存在 jpeg 中。 The server does not use qt.
服务器不使用 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 写入套接字以及如何在 python 中读取它以供以后保存? QImage is a little unclear to me.
QImage 对我来说有点不清楚。
One option could be converting QIMage
to base64
data and you can de-serialize this later in python side:一种选择是将
QIMage
转换为base64
数据,您可以稍后在 python 端反序列化:
in c++ side在 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());
in python side:在 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))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.