我需要制作一个函数来复制一张镜像的图片。我已经编写了镜像图片的代码,但它并不起作用,我也不知道为什么,因为我已经追踪代码,这应该是可以实现镜像图片的。下面是代码:
def invert(picture):
width = getWidth(picture)
height = getHeight(picture)
for y in range(0, height):
for x in range(0, width):
sourcePixel = getPixel(picture, x, y)
targetPixel = getPixel(picture, width - x - 1, height - y - 1)
color = getColor(sourcePixel)
setColor(sourcePixel, getColor(targetPixel))
setColor(targetPixel, color)
show(picture)
return picture
def main():
file = pickAFile()
picture = makePicture(file)
newPicture = invert(picture)
show(newPicture)
请问有人能解释一下问题出在哪里吗?谢谢。
show(picture)
,返回图片也应缩进:return picture
- bozdozmirror
;-),以反映您本地文件中的内容... - Gauthier Boaglio