决定在 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)