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

Image 循环(for loop),即使是jython中图片中的像素,image,loops,for-loop,jython,pixels,Image,Loops,For Loop,Jython,Pixels,我需要使用一个for循环来循环图片中的每个偶数像素。我想我已经接近这个代码了,但是jython不喜欢它,我也不知道为什么(第二个for循环) 任何帮助都将不胜感激 这是我的完整代码,如果有帮助的话。该项目的重点是通过将所有偶数像素移动到大小为一半的新空白图片来调整图片大小 def main(): #Allows the user to pick a picture pic = makePicture(pickAFile()) show(pic) #Finds the

我需要使用一个for循环来循环图片中的每个偶数像素。我想我已经接近这个代码了,但是jython不喜欢它,我也不知道为什么(第二个for循环)

任何帮助都将不胜感激

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

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)

不在y值的循环上进行制表是否存在问题?这样的文本结构能解决问题吗?(顺便说一下,将第三个参数添加到range()函数可以定义步长值,而不是默认的1。)


不在y值的循环上进行制表是否存在问题?这样的文本结构能解决问题吗?(顺便说一下,将第三个参数添加到range()函数可以定义步长值,而不是默认的1。)


我想我的问题中确实有这样的结构,对不起。感谢您提供有关第三个参数的提示。我的错误是,我试图将字符串传递给一个需要整数的方法。错误在第三行。这是指图片吗?根据你发布的代码,这将是我能想到的唯一错误来源。可能尝试使用int(pic)强制转换为int?除此之外我真的不知道。我想我的问题中确实有这样的结构,对不起。感谢您提供有关第三个参数的提示。我的错误是,我试图将字符串传递给一个需要整数的方法。错误在第三行。这是指图片吗?根据你发布的代码,这将是我能想到的唯一错误来源。可能尝试使用int(pic)强制转换为int?除此之外我真的不知道。
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)
for x in range(0, width, 2):
    for y in range(0, height, 2):
        px = getPixels(pic, x, y)