2010-10-21 108 views
0

嘿, 我不知道如何讓Jython意識到像素是(0,0,0)或(255,255,255)。基本上我只是試圖將所有白色像素轉換爲黑色,反之亦然。 以下是我的沙發:S更改黑色像素爲白色,反之亦然

def changeBlackWhite(picture): 
    for x in range(getWidth(picture)): 
     for y in range(getHeight(picture)): 
      px = getPixel(picture, x, y) 
      pxRed = getRed(px) 
      pxBlue = getBlue(px) 
      pxGreen = getGreen(px) 
      if pxRed == '255': 
       if pxBlue == '255': 
        if pxGreen == '255': 
         setRed(px, 0) 
         setBlue(px, 0) 
         setGreen(px, 0) 

幫助? :)

回答

0

我不知道你用什麼庫,但我認爲getRed()會返回整數,而不是字符串。相反:

if pxRed == '255': 

試比較整數

if pxRed == 255: 
相關問題