正在编写python程序以反转GIF图像的颜色,收到错误

正在编写python程序以反转GIF图像的颜色,收到错误,python,image,Python,Image,我目前正试图编写一个程序,读取GIF文件并在屏幕上显示反转图像。这是一个类,因此我不能下载任何附加组件,如PIL。我最初的代码包括获取图像的大小,并使用这些尺寸作为宽度和高度,但当我这样做时,我在“inversePhoto=PhotoImage(宽度=500,高度=250)”这一行上得到了一个错误,这就是为什么我现在用已知的图像尺寸替换“w”和“h”。从那时起,我收到了一个新的错误: Traceback (most recent call last): File "C:/Users/Alex

我目前正试图编写一个程序,读取GIF文件并在屏幕上显示反转图像。这是一个类,因此我不能下载任何附加组件,如PIL。我最初的代码包括获取图像的大小,并使用这些尺寸作为宽度和高度,但当我这样做时,我在“inversePhoto=PhotoImage(宽度=500,高度=250)”这一行上得到了一个错误,这就是为什么我现在用已知的图像尺寸替换“w”和“h”。从那时起,我收到了一个新的错误:

Traceback (most recent call last):
  File "C:/Users/Alexa/Documents/CS 299/InverseColors.py", line 31, in <module>
    r,g,b = getRGB(photo, x, y)
  File "C:/Users/Alexa/Documents/CS 299/InverseColors.py", line 13, in getRGB
    value = photo.get(x, y)
  File "C:\Python33\lib\tkinter\__init__.py", line 3438, in get
    return self.tk.call(self.name, 'get', x, y)
_tkinter.TclError: pyimage1 get: coordinates out of range

当我运行它时,我没有收到任何错误,它看起来是反向的…你能发布一个指向gif的链接吗?这很奇怪…我在另一台计算机上运行了该程序,它运行时没有错误。。然而,它只显示了倒转图像的一半,并将其翻转过来。不知道为什么会这样。我在我的endNevermind上看到了相同的东西,我解决了这个错误——我把x和y混合在一条直线上(在反函数中)
# InverseColors.py

# This program is designed to read a GIF file and display the inverse(negative) of its image

from tkinter import *
import struct

root = Tk()

def getRGB(photo, x, y):
    value = photo.get(x, y)
    return tuple(map(int, value.split(" ")))
def getImageSize(fileName):
    handle = open(fileName, 'rb')
    head = handle.read(24)
    if len(head) != 24:
        return
    width, height = struct.unpack('>ii', head[16:24])
    return width, height
def inverse(image, r, g, b, x, y):
    image.put("#%02x%02x%02x" % ((255-r),(255-g),(255-b)), (y,x))

w, h = getImageSize("picture.gif")
photo = PhotoImage(file="picture.gif")
inversePhoto = PhotoImage(width=500, height=250)

for x in range(0,500):
    for y in range(0,250):
        r,g,b = getRGB(photo, x, y)
        inverse(inversePhoto, r, g, b, x, y)

label = Label(root, image=inversePhoto)
label.grid()

root.mainloop()