简体   繁体   English

引发 UnidentifiedImageError(PIL.UnidentifiedImageError: 无法识别图像文件 <_io.BytesIO object at 0x0000018CA596D350>

[英]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)

Docs for reference:参考文档

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.

相关问题 PIL.UnidentifiedImageError:无法识别图像文件 <_io.BytesIO object - PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object Python 错误:PIL.UnidentifiedImageError:无法识别图像文件 &lt;_io.BytesIO object at 0x1144e9860&gt; - Python error: PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x1144e9860> UnidentifiedImageError: 无法识别图像文件 &lt;_io.BytesIO object at 0x000002154C6AE400&gt; - UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x000002154C6AE400> PIL 无法识别 io.BytesIO object 的图像文件 - PIL cannot identify image file for io.BytesIO object PIL.UnidentifiedImageError:无法识别图像文件'/NGC-DL-CONTAINER-LICENSE' - PIL.UnidentifiedImageError: cannot identify image file '/NGC-DL-CONTAINER-LICENSE' 使用 PIL 打开 Tif 文件“PIL.UnidentifiedImageError:无法识别图像文件” - Opening Tif file with PIL “PIL.UnidentifiedImageError: cannot identify image file” PIL.UnidentifiedImageError:无法识别图像文件'image-playground/.DS_Store' - PIL.UnidentifiedImageError: cannot identify image file 'image-playground/.DS_Store' Discord.py 错误,PIL.UnidentifiedImageError: 无法识别图像文件 - Discord.py error, PIL.UnidentifiedImageError: cannot identify image file PIL.UnidentifiedImageError: 无法识别图像文件 &#39;dataset\\\\Thumbs.db&#39; - PIL.UnidentifiedImageError: cannot identify image file 'dataset\\Thumbs.db' PIL.UnidentifiedImageError: 无法识别图像文件 [当我使用 Keras 而不是 PILLOW 时] - PIL.UnidentifiedImageError: cannot identify image file [When I using Keras and not PILLOW]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM