【问题标题】:How to make half a photo negative如何使半张照片负片
【发布时间】:2014-10-24 16:59:55
【问题描述】:

我有我的代码来否定一张照片,但我正在努力弄清楚如何只否定图像的左侧或右侧的一半。下面是负数的代码,我知道我无法弄清楚如何获得所需的一半像素。

def negative(picture):
  for px in getPixels(picture):
      red=getRed(px)
      green=getGreen(px)
      blue=getBlue(px)
      negColor=makeColor(255-red,255-green,255-blue)
      setColor(px, negColor)

【问题讨论】:

    标签: image jython jes


    【解决方案1】:

    首先,您需要找到图片的宽度并将其除以 2

    halfWidth = getWidth(picture) / 2
    

    因为您不想遍历所有无法使用for px in getPixels(picture): 的像素。您需要的是 range() 函数和 2 个 for 循环,例如

    # Iterate along the Y axis
    for y in range(0, getHeight(picture)):
    
      # Iterate along the X axis but only for half the width
      for x in range(0, halfWidth):
    
        # Get the pixel at X, Y coordinate from picture
        px = getPixel(picture, x ,y)
    

    您的其余代码应该可以使用它。

    【讨论】:

      猜你喜欢
      • 2021-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多