简体   繁体   English

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

[英]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.

相关问题 如何从 python 服务器正确发送消息到 c++ 客户端? - How to send messages properly from python server to c++ client? 使用C ++ Client通过Zmq发送JSON对象-Python服务器 - Send JSON Object through Zmq with C++ Client - Python Server Zeromq:如何从python客户端向C ++服务器发送长度超过30个字符的消息 - Zeromq : How to send message longer than 30 character from python client to c++ server 使用 sockets 将字符串从一台计算机上的 C++ 客户端发送到另一台计算机上的 Python 服务器。 获取`发送:错误的文件描述符` - Using sockets to send a string from a C++ client on one computer to a Python server on another. Getting `send: Bad file descriptor` 客户端服务器python -C ++ - client server python -C++ 从客户端C发送套接字,服务器Python问题 - Socket Send from Client C, Server Python Issue 使用套接字将波斯字符串从 C# 服务器发送到 python 客户端 - Send Persian string from C# server to python client with socket 从 C++ 服务器到 python 客户端接收不同大小的字节 - receiving bytes in different sizes from c++ server to python client 将char数组从C ++(客户端)传递给python(服务器)Winsock - Passing char array from c++ (client) to python(server) winsock 从python中的服务器发送一些行到QT(C ++)客户端 - Sending some lines from server in python to QT(C++) client
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM