【问题标题】:Use while loop to scan through pixels in a picture使用 while 循环扫描图片中的像素
【发布时间】:2014-10-18 19:46:18
【问题描述】:

我不知道如何使用while 循环来扫描所有像素。

我可以使用 for 循环来做到这一点,但如何只使用 while 循环来做到这一点??

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

________________________________

def question410():
  pic = makePicture(getMediaPath("barbara.jpg"))
  width = getWidth(pic)
  height = getHeight(pic)
  canvas = makeEmptyPicture(width,height)

  explore(pic)
  scale = 2


  x = 0
  y = 0
 while x < width:
   while y < height:
      px = getPixel(pic,x,y)
      colour = getColor(px)
      tgtPx = getPixel(canvas,x,y)
      setColor(tgtPx,colour)

      x=x+1
      y=y+1
      print x, y



  explore(canvas)

【问题讨论】:

  • 您是否尝试过使用while 循环自己编写代码?如果有,请分享。
  • 我正在学习在 JES 中执行此操作。我尝试过类似 while x

标签: jes


【解决方案1】:

您的问题似乎是内部循环而不是外部循环内的 x 变量的增量。

while x < width:
  while y < height:
    # Do stuff
    y = y + 1
  x = x + 1

【讨论】:

    【解决方案2】:

    您必须在每个循环中创建计数器变量和 ++ 或 -- 它们,直到出现中断条件。` 举例

    x = 1
    While (x != rangeofpixels) 
    { dostuff; x++ }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-03-28
      • 2019-11-28
      • 2023-01-08
      • 1970-01-01
      • 2013-02-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多