“tuple”对象没有属性“mode”

2024-06-01 11:31:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我基本上是python的初学者,说“tuple”对象没有“attribute”模式,就不能理解这个错误

import os
import random
from PIL import Image
from PIL import ImageFilter


Mothmando = Image.open(r"C:\Users\Epicd\Desktop\Fortnite\Mothmando.png")
France = Image.open(r"C:\Users\Epicd\Desktop\Fortnite\France.png")
FranceRGB = France.convert('RGB')
Crimson_Scout = Image.open(r"C:\Users\Epicd\Desktop\Fortnite\Crimson_Scout.png")

Choice = (Mothmando, Crimson_Scout)

Image.Image.paste(Choice, France, box=(1,1,600,450), mask=Choice)
#FranceRGB.paste(Crimson_Scout, France, box=(1,1,600,450), mask=Crimson_Scout)
FranceRGB.save(r"C:\Users\Epicd\Desktop\Fortnite\Pain1.png")

这是代码,但程序不断抛出错误

Traceback (most recent call last):
  File "C:\Users\Epicd\Desktop\Fortnite\Fortnite.py", line 14, in <module>
    Image.Image.paste(Choice, France, box=(1,1,600,450), mask=Choice)
  File "C:\Python375\lib\site-packages\PIL\Image.py", line 1508, in paste
    if self.mode != im.mode:
AttributeError: 'tuple' object has no attribute 'mode'
[Finished in 0.135s]

如何修复此错误


Tags: imageimportpilpng错误userspastedesktop
1条回答
网友
1楼 · 发布于 2024-06-01 11:31:10

似乎paste()的第一个输入,或者我不知道的掩码输入,必须是一个图像。但是,您正在传递一组图像

你有没有试过这样的方法:

for c in Choice:
    FranceRGB.paste(c, France, box=(1,1,600,450), mask=c)

相关问题 更多 >