我正在尝试编写一个函数来接收图片,将其缩小两倍并将该图片放入空白画布中。我觉得我的输入正确,但它一直给我错误:
getPixel(picture,x,y): y (= 480) is less than 0 or bigger than the height (= 479)
错误是:
Inappropriate argument value (of correct type).
An error occurred attempting to pass an argument to a function.
这是我的代码:
def makeSmaller(Picture):
pic = Picture
width = getWidth(pic)
height = getHeight(pic)
canvas = makeEmptyPicture(width /2 , height /2)
sourceX = getWidth(canvas)
for x in range (0, getWidth(canvas)- 1):
sourceY = getHeight(canvas)
for y in range (0, getHeight(canvas)- 1):
color = getColor(getPixel(pic, sourceX, sourceY))
setColor(getPixel(canvas, x, y), color)
sourceY = sourceY + 2
sourceX = sourceX + 2
show(pic)