开发者

Change Black pixels to white and vice versa

Hey there, I can't figure out how to make Jython realize that the pixel is either (0,0,0) or (255,255,255). Basically I'm just trying to convert all white pixels to black and vice versa.开发者_如何转开发 Here's what i have sofar :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)

Help?! :)


I don't know what library you use, but I think that getRed() will return integer, and not string. Instead:

if pxRed == '255':

try comparing to integer:

if pxRed == 255:
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜