导入 PIL 映像存在问题



我想在 PIL 中使用图像模块

如果我执行以下操作

   import PIL
    PIL.Image.open()

它说没有名为 Image 的模块。

但以下工作正常

    from PIL import Image

我正在使用一个软件包,无法更改 PIL。Image.open()

如何克服这个问题。

谢谢

尝试:

import PIL.Image

这就是你想要的吗?

鸭子打字来救援。 PIL实际上不必是一个模块,它只需要是一个具有属性 Image 的对象。

>>> from PIL import Image
>>> class MakePIL(object):
    def __init__(self, Image):
        self.Image = Image
>>> PIL = MakePIL(Image)
>>> PIL.Image
<module 'PIL.Image' from 'C:Python27libsite-packagesPILImage.pyc'>
>>> PIL.Image.open(r'c:temptemp.jpg')
<PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=400x250 at 0x2C88D78>

你可以试试:

from PIL import Image as MyImage

并使用我的图像

最新更新