开发者

Change Black pixels to white and vice versa

开发者 https://www.devze.com 2023-01-21 07:56 出处:网络
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.开发者_如何转

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

精彩评论

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