简体   繁体   English

在Python中水平翻转图像时出错

[英]Error when flipping an image horizontally in Python

I need to flip a picture horizontally, without using the reverse function , I thought I had it right but the error I get is 我需要水平翻转图片, 而不使用反向功能 ,我认为我做得对,但我得到的错误是

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'

The code I have is 我的代码是

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

What does the error mean? 错误是什么意思? and how do I fix it? 以及如何解决?

The interpreter is complaining that it can't find the getPixel function inside the module graphics ; 解释器抱怨它无法在模块graphics找到getPixel函数; it's img.getPixel , not graphics.getPixel . 它是img.getPixel ,而不是graphics.getPixel

        pic1 = graphics.getPixel(x,y)
        pic2 = graphics.setPixel(X-x,y)

Probably should be: 可能应该是:

        pic1 = img.getPixel(x,y)
        pic2 = img.setPixel(X-x,y)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM