Python代码用于创建图像的镜像并将其与一定量的白色混合。

时间:2012-10-04 22:34:32

标签: python colors flip

我是Python的新手,我正在尝试用Python学习操作图片。下面的这段代码是创建图片的镜像,然后将其淡化为白色。但是当我执行代码“错误是:'int'和'function'时,我得到了下面的错误 不适当的论证类型。 尝试使用无效类型的参数调用函数。这意味着你做了一些事情,比如尝试将字符串传递给期望整数的方法。“我不确定是什么导致了这个错误,我需要帮助。

def blendWhite(pixcel, fadeAmount):
    newRed = 255 * fadeAmount + getRed(pixel) * (1 - fadeAmount)
    newGreen = 255 * fadeAmount + getGreen(pixel) * (1 - fadeAmount)
    newBlue = 255 * fadeAmount + getBlue(pixel) * (1 - fadeAmount)
    setColor(pixel, makeColor(newRed, newGreen, newBlue))

def copyAndMirrorCat():
    catFile = getMediaPath("caterpillarSmall.jpg")
    catPict = makePicture(catFile)
    width = getWidth(catPict)
    height = getHeight(catPict)
    canvas = makeEmptyPicture(width, height * 2)
    # Now, do the actual copying
    for x in range(0, width):
        for y in range(0, height):
            color = getColor(getPixel(catPict, x, y))
            setColor(getPixel(canvas, x, y), color)
            h = height * 2
            fadeAmount(y, h)
            blendWhite(getPixel(canvas, x, (height * 2) - y - 1), fadeAmount)
    show(catPict)
    show(canvas)
    return canvas

def fadeAmount(y, h):
    fm = (h - y) / float(h) + 0.15
    if fm > 1:
        fm = 1
    return fm  

结果如下:http://imageshack.us/a/img442/326/mirrorlinearwithwhite.jpg

1 个答案:

答案 0 :(得分:1)

如果你看一下你说的行:

fadeAmount(y,h) 
blendWhite(getPixel(canvas,x,(height*2)-y-1),fadeAmount)

您将看到在不将值存储在变量中的情况下调用fadeAmount()。然后尝试将该函数传递给blendWhite()。这不行。您需要存储值并传递它,例如:

fa = fadeAmount(y,h)
blendWhite(getPixel(canvas,x,(height*2)-y-1),fa)

......或者只是说一句话:

blendWhite(getPixel(canvas,x,(height*2)-y-1),fadeAmount(y,h))