Reputation: 71
I receive a bytes, which is converted from an image from Android client, how can I convert it to image on 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. How can I solve this?
PS:data
is complete because I save the image completely by using Eclipse.
Upvotes: 3
Views: 12222
Reputation: 71
I have already solve the problem.I made a stupid mistake that the buffersize
I set for socket.recv
is too short.
I set a longer buffersize
like 100000000, and saving the image is easy like:
f = open('D:\\2.jpg', 'wb')
f.write(data)
f.close()
Upvotes: 4