Python PIL:转换RGBA-> P - ValueError:图像有错误的模式

时间:2013-11-12 17:56:45

标签: python png python-imaging-library

使用Python Imaging Library(PIL)我得到了一个:

"ValueError: image has wrong mode"

尝试将RGBA模式图像转换为P模式图像时。我找不到任何证据证明这是可能的。我在convert()方法中找到的材料并没有说明它是不可能的。我想知道我做错了什么或者这是不可能的。

这是我的代码:

from PIL import Image

transImage = Image.open("transparent_8_bit.png")
print transImage.mode

transImageRGBA = transImage.convert("RGBA")
print transImageRGBA.mode

transImageP = transImageRGBA.convert('P', palette=Image.ADAPTIVE)
print transImageP.mode

这是图片“transparent_8_bit.png”:http://s24.postimg.org/4xqzu9n4h/transparent_8_bit.png

输出应为:

P
RGBA
P

然而,我明白了:

P
RGBA
Traceback (most recent call last):
  File "mode_test.py", line 7, in <module>
    transImageP = transImageRGBA.convert('P', palette=Image.ADAPTIVE)
  File "/Library/Python/2.7/site-packages/PIL/Image.py", line 689, in convert
    im = self.im.quantize(colors)
ValueError: image has wrong mode

PIL是否无法做到这一点?

感谢您的帮助!

0 个答案:

没有答案