[英]python convert bytes to image
I receive a bytes, which is converted from an image from Android client, how can I convert it to image on Python? 我收到一个字节,该字节是从Android客户端的图像转换而来的,如何将其转换为Python图像? I use these code:
我使用以下代码:
img = Image.open(BytesIO(data))
img.show()
img.save('D:\\1.jpg')
but I can only get an incomplete image like: 但我只能得到一个不完整的图像,例如:
The image on the right is what I'm trying to send to Python, and the left is what I get. 右边的图像是我要发送给Python的图像,左边的图像是我得到的图像。 How can I solve this?
我该如何解决?
PS: data
is complete because I save the image completely by using Eclipse. PS:
data
是完整的,因为我使用Eclipse完全保存了图像。
I have already solve the problem.I made a stupid mistake that the buffersize
I set for socket.recv
is too short. 我已经解决了疑难问题作出了愚蠢的错误,该
buffersize
我的设置socket.recv
太短。
I set a longer buffersize
like 100000000, and saving the image is easy like: 我设置了更长的
buffersize
例如100000000,并且保存图像很容易:
f = open('D:\\2.jpg', 'wb')
f.write(data)
f.close()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.