为什么在尝试从 io.bytesIO 对象打开图像时会引发 PIL.UnidentifiedImageError ?
简而言之,当尝试使用字节数据打开图像时,不幸的是我最终遇到了错误。为了更清楚起见,这里有一些代码。
test2.py:test.py
logo = b"iVBORw0KGgoAAAA ... "
#(It's 60k characters long don't worry about it)
:
import test2 as pim
import io
from PIL import Image, ImageTk
sol = io.BytesIO(pim.logo)
image = Image.open(sol)
显然由于某种奇怪的原因,我最终遇到了这个错误:
PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x0000028D819373D0>
我尝试在其他帖子上搜索。我找到了一些类似的解决方案,但没有一个解决方案有效。
In short terms, when trying to open an image using byte data, I unfortunately end up with an error. Here is some of the code for more clarity.
test2.py:
logo = b"iVBORw0KGgoAAAA ... "
#(It's 60k characters long don't worry about it)
test.py:
import test2 as pim
import io
from PIL import Image, ImageTk
sol = io.BytesIO(pim.logo)
image = Image.open(sol)
Apparenly for some strange reason, I end up with this error:
PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x0000028D819373D0>
I've tried searching on other posts. I found some similar ones, but none of the solutions worked.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
@martineau 实际上回答了这个问题,但这里有一个快速启动:
转换 base64 数据,在 bytesio 类中使用它并将其放入图像中:
@martineau actually answered the question but here is a quick runup:
Convert base64 data, use it in a bytesio class and put it into an image: