0

我需要水平翻转图片,而不使用反向功能,我以为我做对了,但我得到的错误是

Traceback (most recent call last):
  File "<pyshell#9>", line 1, in <module>
    Flip("bm.gif","bm.ppm")
  File "C:\Users\....ImageProcessingSKLT.py", line 133, in Flip
    pic1 = graphics.getPixel(x,y)
AttributeError: 'module' object has no attribute 'getPixel'

我的代码是

def Flip(image1, image2):
    img = graphics.Image(graphics.Point(0, 0), image1)
    X = img.getWidth()
    Y = img.getHeight()
    for y in range(Y//2):
        for x in range(X):
            pic1 = graphics.getPixel(x,y)
            pic2 = graphics.setPixel(X-x,y)
            temp = graphics.getColor(pic1)
            graphics.setColor(pic1,getColor(pic2))
            graphics.setColor(pic2,temp)
            image2 = pic2
    return image2

错误是什么意思?我该如何解决?

4

2 回答 2

1

解释器抱怨它在模块中找不到getPixel函数graphics;是img.getPixel,不是graphics.getPixel

于 2013-04-14T23:47:38.063 回答
1
        pic1 = graphics.getPixel(x,y)
        pic2 = graphics.setPixel(X-x,y)

大概应该是:

        pic1 = img.getPixel(x,y)
        pic2 = img.setPixel(X-x,y)
于 2013-04-14T23:47:40.890 回答