3

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.

3
  • Have you checked to see if data is complete and the correct length? Commented Jun 21, 2018 at 4:41
  • This answer might help you. [stackoverflow.com/questions/18491416/… Commented Jun 21, 2018 at 4:41
  • @IgnacioVazquez-Abrams it is complete because I save the image completely by using Eclipse. Commented Jun 21, 2018 at 4:44

1 Answer 1

4

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()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.