[英]raise UnidentifiedImageError( PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x0000018CA596D350>
I'm getting the error 'raise UnidentifiedImageError( PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x0000018CA596D350>' in the following code:我在以下代码中收到错误“raise UnidentifiedImageError(PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x0000018CA596D350>”:
import io
from PIL import Image
file = io.BytesIO(str.encode('D:/Downloads/imagens/0b4d4db99a7b8ecba24909d277556de8.png'))
img1=Image.open(file)
img1.show()
There's much other questions like this, but none of them seem to be the same problem.还有很多其他类似的问题,但似乎都不是同一个问题。 If I take the 'str.encode' off the error goes to "TypeError: a bytes-like object is required, not 'str'"如果我去掉'str.encode',错误会转到“TypeError:需要一个类似object的字节,而不是'str'”
Did you mean to open that file?你的意思是打开那个文件吗?
img1 = Image.open('D:/Downloads/imagens/0b4d4db99a7b8ecba24909d277556de8.png')
# or
with open('D:/Downloads/imagens/0b4d4db99a7b8ecba24909d277556de8.png', 'rb') as fh:
img1 = Image.open(fh)
This is a lazy operation;这是一个惰性操作; this function identifies the file, but the file remains open and the actual image data is not read from the file until you try to process the data (or call the load() method).此 function 识别文件,但文件保持打开状态,并且在您尝试处理数据(或调用 load() 方法)之前不会从文件中读取实际图像数据。 See new().见新()。 See File Handling in Pillow.请参阅 Pillow 中的文件处理。
Parameters参数
fp
– A filename (string), pathlib.Path object or a file object.fp
– 文件名(字符串)、pathlib.Path object 或文件 object。 The file object must implement file.read, file.seek, and file.tell methods, and be opened in binary mode.文件 object 必须实现 file.read、file.seek 和 file.tell 方法,并以二进制模式打开。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.