Graphics 将黑色像素更改为白色,反之亦然
嘿,那里, 我不知道如何让Jython意识到像素是(0,0,0)或(255255)。基本上我只是想把所有的白色像素转换成黑色,反之亦然。 这是我目前所拥有的:sGraphics 将黑色像素更改为白色,反之亦然,graphics,jython,pixels,Graphics,Jython,Pixels,嘿,那里, 我不知道如何让Jython意识到像素是(0,0,0)或(255255)。基本上我只是想把所有的白色像素转换成黑色,反之亦然。 这是我目前所拥有的:s def changeBlackWhite(picture): for x in range(getWidth(picture)): for y in range(getHeight(picture)): px = getPixel(picture, x, y) px
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)
救命?!:) 我不知道您使用的是什么库,但我认为
getRed()
将返回整数,而不是字符串。相反:
if pxRed == '255':
尝试与整数进行比较:
if pxRed == 255: