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はこれを行うことができないのですか?
ご協力いただきありがとうございます!