python C PIL open()方法不能使用BytesIO
发布时间:2023-12-22 05:17:09 所属栏目:Python 来源:DaWei
导读: 由于某种原因,当我尝试从BytesIO蒸汽制作图像时,它无法识别图像.这是我的代码:
from PIL import Image,ImageGrab
from io import BytesIO
i = ImageGrab.grab()
i.resize((1280,7
from PIL import Image,ImageGrab
from io import BytesIO
i = ImageGrab.grab()
i.resize((1280,7
|
由于某种原因,当我尝试从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). (编辑:吉安站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 格式化django中的电话号码
- python – 将numpy.array中的每个元素与numpy.array中的每个
- python C 在扫描文档中分割文本行
- python – Django 1.7 makemigrations – ValueError:无法
- Python:如何找到使用matplotlib绘制的图形的斜率?
- Python,如何将状态/ update_with_media发布到Twitter?
- python – IRR实现中使用的数值方法是什么?
- python – 带smtp.gmail的Django电子邮件SMTPAuthenticatio
- python C 从appengine应用程序上传文件到谷歌云存储
- python – pip安装eyeD3模块.找不到libmagic
推荐文章
站长推荐
- 错误:输入’for’Python时没有可行的替代方案
- Python – Multiprocessing.processes从可执行文
- Python C 有没有办法等待os.unlink()或os.remove
- 使用python,自动确定用户当前时区的最准确方法是
- python C boto dynamodb2:我可以只使用范围键查
- 在Python Celery中,如何在连续的工作调用中持久保
- python – 如何克服 – 在windows上使用文件名或
- Python Django:在视图中,最好是为对象添加属性还
- 如何获取numpy.random.choice的索引? C Python
- Python 3:接收用户输入,包括换行符
