循环(for循环)即使是jython中图片中的像素

loop (for loop) though even pixels in a picture in jython

我需要使用单个 for 循环遍历图片中的每个偶数像素。我想我已经接近这段代码了,但 jython 不喜欢它而且我不知道为什么(第二个 for 循环的东西)。

for x in range(0, width):
  for y in range(0, height):
    px = getPixels(pic, x, y)

如有任何帮助,我们将不胜感激。

如果有帮助,这是我的完整代码。该项目的重点是通过将所有偶数像素移动到一半大小的新空白图片来调整图片大小。

def main():
  #Allows the user to pick a picture
    pic = makePicture(pickAFile())
    show(pic)
    #Finds the width and height of the selected picture
    width = getWidth(pic)
    height = getHeight(pic)

  #Finds and divides width accordingly
    if width % 2 == 0:
      newW = width/2
    else:
      newW = width/2+1

  #Finds and divides height accordingly  
    if height % 2 == 0:
      newH = height/2
    else:
      newH = height/2+1

for x in range(0, width, 2):
  for y in range(0, height, 2):
    px = getPixels(pic, x, y)

不在循环上按 tab 键获取 y 值是否有问题?像这样构建文本是否可以解决问题? (顺便说一句,向 range() 函数添加第三个参数可以让您定义步长值而不是默认值 1。)

for x in range(0, width, 2):
    for y in range(0, height, 2):
        px = getPixels(pic, x, y)