image - ZeroMQ pyzmq通过tcp发送jpeg图像

标签 image jpeg zeromq pyzmq

我试图通过 ZeroMQ 连接与 pyzmq 发送 jpeg 图像文件,但输出是输入大小的 3 倍,并且不再是有效的 jpeg。我加载图像并发送...

f = open("test1.jpg",'rb')
strng = f.read()
socket.send(strng)
f.close()

我接收并保存...

message = socket.recv()
f = open("test2.jpg", 'w')
f.write(str(message))
f.close()

我是 zmq 新手,我找不到任何有关发送图像的信息。有没有人通过 ZeroMQ 发送图像,或者对如何查找问题有任何想法?

最佳答案

在发送文件之前,您可以对其进行“base64”编码并在收到时对其进行解码。

发送:

import base64
f = open("test1.jpg",'rb')
bytes = bytearray(f.read())
strng = base64.b64encode(bytes)
socket.send(strng)
f.close()

接收:

import base64
message = socket.recv()
f = open("test2.jpg", 'wb')
ba = bytearray(base64.b64decode(message))
f.write(ba)
f.close()

关于image - ZeroMQ pyzmq通过tcp发送jpeg图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24791633/

相关文章:

ios - 在 ImageView 上加载图像时内存增加?

java - 如何在java中将存储在Byte数组中的JPG数据转换为BGR数据

来自硬盘的 css 图像

c++ - 如何用imcodecs编译opencv?

PHP fatal error : Class 'imagecreatefromjpeg' not found

c# - 根据对象枚举值将图像绑定(bind)到组合框

python - 带有元数据的 HEIC 到 JPEG 转换

javascript - 如何在运行时检查此 TypeScript 代码中的 instanceof?

zeromq 和 bind_to_random_port - 如何选择端口

python - 为什么 ZeroMQ 轮询器没有收到消息(python)?