我正在为一个项目编程,以便可以轻松确定要为网站填充图像的像素数。但是,我遇到了此错误:getpixel()接受2个位置参数,但给出了3个。 我的代码如下:
from PIL import Image
import PIL.ImageOps
background = Image.open("background.png")
target = input("Please enter the name of your image (including file type)")
targetImage = Image.open(target)
area = targetImage.size
targetColouredCoords = []
newArea = (area[0] + 1, area[1] + 1)
borderedTarget = PIL.ImageOps.expand(targetImage, border=10, fill="black")
targetValues = list(borderedTarget.getdata())
def analyser():
pixelOne = 1
pixelTwo = 1
completedSearch = 0
currentPixel = borderedTarget.getpixel(pixelOne, pixelTwo)
def colourChecker():
if currentPixel != (0, 0, 0):
targetColouredCoords.append((pixelOne, pixelTwo))
while completedSearch != len(targetValues):
while pixelOne != newArea[0]:
while pixelTwo != newArea[1]:
colourChecker()
pixelTwo += 1
completedSearch += 1
pixelTwo = 1
pixelOne += 1
analyser()
我在整个代码中唯一提供3个参数的行是18,但是我不明白这行代码是不正确的,还是突出显示为问题的代码(第26行)如何。在消除错误之前,我无法继续编写代码,因此非常感谢您的帮助。