我需要水平翻转图片,而不使用反向功能,我认为我没错,但我得到的错误是
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
错误是什么意思?以及如何修复它?
答案 0 :(得分:1)
解释器抱怨它在模块getPixel
内找不到graphics
函数;它是img.getPixel
,而不是graphics.getPixel
。
答案 1 :(得分:1)
pic1 = graphics.getPixel(x,y)
pic2 = graphics.setPixel(X-x,y)
可能应该是:
pic1 = img.getPixel(x,y)
pic2 = img.setPixel(X-x,y)