Pillow PixelAccess TypeError: function takes exactly 1 argument (4 given)

Pillow PixelAccess TypeError: function takes exactly 1 argument (4 given)

我正在尝试遍历某些像素并使用 PixelAccess 对其进行编辑。出于某种原因,当我尝试设置像素时,Python 给我 TypeError: function takes exactly 1 argument (4 given)

pixels[(x, y)] = pix

是准确的代码。

Traceback (most recent call last):
  File "./gen_shuttletiles.py", line 86, in <module>
    main()
  File "./gen_shuttletiles.py", line 76, in main
    pixels[(x, y)] = pix
TypeError: function takes exactly 1 argument (4 given)

pix 是图像 RGBA 值的四元组数字。 我试图通过添加一些零来更改元组中项目的数量,但错误中给出的计数确实增加了。

弄明白了,图像处于 P 模式,所以我必须事先将其转换为 RGBA