PIL open() method not working with BytesIO

前端 未结 1 1748
执念已碎
执念已碎 2020-11-29 08:39

For some reason, when I try to make an image from a BytesIO steam, it can\'t identify the image. Here is my code:

from PIL import Image, ImageGrab
from io im         


        
相关标签:
1条回答
  • 2020-11-29 08:55

    Think of BytesIO as a file object, after you finish writing the image, the file's cursor is at the end of the file, so when Image.open() tries to call output.read(), it immediately gets an EOF.

    You need to add a output.seek(0) before passing output to Image.open().

    0 讨论(0)
提交回复
热议问题