小编Yod*_*abe的帖子

不能在 PIL 库中的 png 文件上使用 Image.putalpha()。OSError:无法将模式 PA 写为 PNG

决定在 jupyter notebook 中尝试 PIL lib。我有一个 png 格式的蓝色图像(没有别的)。

想让它半透明。所以我做了:

from PIL import Image
blue = Image.open("blue_color.png")
Run Code Online (Sandbox Code Playgroud)

当我通过 jupyter 打开图像时,一切都很好。但后来我应用 .putalpha() 方法:

blue.putalpha(128)
Run Code Online (Sandbox Code Playgroud)

得到这个:

KeyError                                  Traceback (most recent call last)
~\Anaconda3\lib\site-packages\PIL\PngImagePlugin.py in _save(im, fp, filename, chunk)
    799     try:
--> 800         rawmode, mode = _OUTMODES[mode]
    801     except KeyError:

KeyError: 'PA'

During handling of the above exception, another exception occurred:

OSError                                   Traceback (most recent call last)
~\Anaconda3\lib\site-packages\IPython\core\formatters.py in __call__(self, obj)
    343             method = get_real_method(obj, self.print_method)
    344             if method is not None:
--> 345 …
Run Code Online (Sandbox Code Playgroud)

python python-imaging-library jupyter-notebook

6
推荐指数
1
解决办法
1816
查看次数