我正在使用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))
有人可以告诉我如何解决此问题吗?
答案 0 :(得分:3)
根据documentation,PIL.JpegImagePlugin.JpegImageFile
类是PIL.Image.Image
类的子类。
因此,您的对象是特定类型的Image
,可以用作Image
=)
。