我正在尝试编写一个简单的算法来将图片的大小减半,这对我来说似乎很有意义,但我可能在这里遗漏了一些明显的东西,并且想知道是否有人能指出我正确的方向。
a = pickAFile()
b = makePicture(a)
c = getWidth(b)
d = getHeight(b)
e = (c * 3) / 4
f = (d * 3) / 4
canvas = makeEmptyPicture(e,f)
sourceX = 1
for targetX in range (1, c):
sourceY = 1
for targetY in range (1, d):
color = getColor(getPixel(b, sourceX, sourceY))
setColor(getPixel(canvas, targetX, targetY), color)
sourceY = sourceY + 2
sourceX = sourceX + 2
show(canvas)
show(b)
编辑:当我尝试按现在的方式运行它时,我得到 for 循环的索引越界错误。