首页 > 解决方案 > 在我的代码中遇到错误,但我无法确定原因。(getpixel() 接受 2 个位置参数,但给出了 3 个)

问题描述

我正在为一个项目编程,这样我就可以轻松地确定我想为网站填充多少像素。但是,我遇到了这个错误: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 行)。在删除错误之前,我无法继续编码,因此非常感谢任何帮助。

标签: pythontypeerrorpillow

解决方案


再看一遍,输入必须是一个元组:

getpixel( (pixelOne,pixelTwo) )

资源


推荐阅读