python – PIL open()方法不能使用BytesIO
发布时间:2021-01-24 06:03:49 所属栏目:Python 来源:互联网
导读:由于某种原因,当我尝试从BytesIO蒸汽制作图像时,它无法识别图像.这是我的代码: from PIL import Image, ImageGrabfrom io import BytesIOi = ImageGrab.grab()i.resize((1280, 720))output = BytesIO()i.save(output, format = JPEG)output
由于某种原因,当我尝试从BytesIO蒸汽制作图像时,它无法识别图像.这是我的代码: from PIL import Image,ImageGrab from io import BytesIO i = ImageGrab.grab() i.resize((1280,720)) output = BytesIO() i.save(output,format = "JPEG") output.flush() print(isinstance(Image.open(output),Image.Image)) 并且它抛出的错误的堆栈跟踪: Traceback (most recent call last): File "C:/Users/Natecat/PycharmProjects/Python/test.py",line 9,in <module> print(isinstance(Image.open(output),Image.Image)) File "C:Python27libsite-packagesPILImage.py",line 2126,in open % (filename if filename else fp)) IOError: cannot identify image file <_io.BytesIO object at 0x02394DB0> 我正在使用枕头实施PIL. 解决方法将BytesIO视为文件对象,完成图像编辑后,文件的光标位于文件末尾,因此当Image.open()尝试调用output.read()时,它会立即获得EOF.在将输出传递给Image.open()之前,需要添加一个output.seek(0). (编辑:4S站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- 有GIL时,你可以在Python中竞争条件吗?
- python – 什么是django.utils.functional .__ p
- 使用python中的csv模块写入特定单元格
- python – 更改Jupyter笔记本版本4.x徽标
- Python语言中的函数range()没有给出预期的结果
- python – 将参数传递给apscheduler处理函数
- python – Django Test Client post()返回302,尽
- python – 使用dict参数的带有OR条件的Django过滤
- gettext – Flask-Babel如何在Jinja模板文件中使
- python – SQLAlchemy过滤器查询由相关对象
热点阅读