python - 在我的代码中遇到错误,但我无法确定原因。(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 行)。在删除错误之前,我无法继续编码,因此非常感谢任何帮助。
解决方案
推荐阅读
- javascript - 如何重置更改事件处理程序?
- java - 如何通过单击java中的标签打开新窗口?
- javascript - React SideEffect out of useEffect hook
- azure-cosmosdb-mongoapi - Azure CosmoDB 错误:对列进行排序时出现 pymongo.errors.OperationFailure Bad Request(400)
- algorithm - 非二叉树遍历算法的时间/空间复杂度
- algorithm - 对数组进行排序的算法,其中每个元素距离它应该在的位置 10 个位置
- python-3.x - python mock如何在不执行的情况下测试sql文件
- safari - 如果我编辑 URL 以更改路由并且不打开开发者工具,Safari 14.1.1 中的 sessionStorage 会丢失
- laravel - 在 Eloquent 中,有没有办法在关系查询中使用 sql 函数
- javascript - 为什么我们不能直接在浏览器中调用 ReactDOM 或 React?