如何保持从bu中的插座接收到的图像

2024-10-03 21:30:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在进行一个项目,通过套接字从远程计算机接收图像。由于我不知道图像的大小,我正在逐块接收图像,并保存到io.BytesIO()

    def imgdisplayer():
        nonlocal conn, display
        with io.BytesIO() as f:
            while True:
                bytes = conn.recv(1024)
                if not bytes: break
                f.write(bytes)
            imgobj = pickle.loads(f)

但是我的代码不起作用,我想我对io.BytesIO的理解有误 这里出现的错误是:

TypeError: a bytes-like object is required, not '_io.BytesIO'

有没有人能帮我解决这个问题,或者建议其他方法来做这个过程


Tags: 项目io图像bytes远程defas计算机