PIL-image.open返回错误的类型

时间:2020-01-27 17:59:26

标签: python python-imaging-library

我正在使用PIL的图像库来处理JPG文件。据我了解,调用PIL的open()函数应返回Image类型的对象。但是我遇到一个问题,它返回类型为PIL.JpegImagePlugin.JpegImageFile的对象。这是我正在运行的代码:

from PIL import Image
for filename in os.listdir(""):
    new_filename = filename
    if(filename[0] == '.'):
        new_filename = filename[2:]
    picture = Image.open(new_filename, 'r')
    print(type(picture))

有人可以告诉我如何解决此问题吗?

1 个答案:

答案 0 :(得分:3)

根据documentationPIL.JpegImagePlugin.JpegImageFile类是PIL.Image.Image类的子类。

因此,您的对象是特定类型的Image,可以用作Image =)