将QImage从c ++客户端发送到python服务器

问题描述 投票:-1回答:1

c ++客户端具有QImage,必须通过tcp套接字将其发送到python服务器,并保存在jpeg中。服务器不使用qt。您能解释一下如何正确执行此操作吗?如何将数据从QImage写入套接字,以及如何在python中读取数据以便以后保存?QImage对我来说还不太清楚。

python c++ qimage tcpsocket
1个回答
0
投票

[一个选项可能是将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))
© www.soinside.com 2019 - 2024. All rights reserved.