[英]Why is PIL.UnidentifiedImageError being raised when trying to open an image from an io.bytesIO object?
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:测试2.py:
logo = b"iVBORw0KGgoAAAA ... "
#(It's 60k characters long don't worry about it)
test.py:测试.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.
我找到了一些类似的,但没有一个解决方案有效。
@martineau actually answered the question but here is a quick runup: @martineau 实际上回答了这个问题,但这里有一个快速启动:
Convert base64 data, use it in a bytesio class and put it into an image:转换 base64 数据,在 bytesio class 中使用并放入图像中:
s = base64.b64decode(pim.logo)
sol = io.BytesIO(s)
image = Image.open(sol)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.