相关疑难解决方法(0)

使用PIL的ImageDraw模块

我正在尝试使用PIL的ImageDraw模块进行单独的像素操作.下面的代码应该创建Tkinter canvas小部件.然后打开图像,将一个像素的颜色更改为红色,然后将图像嵌入到画布小部件中.但是,它似乎没有起作用.

我的代码:

import Tkinter
from PIL import ImageTk, Image, ImageDraw


class image_manip(Tkinter.Tk):

    def __init__(self):
        Tkinter.Tk.__init__(self)

        self.configure(bg='red')

        self.ImbImage = Tkinter.Canvas(self, highlightthickness=0, bd=0, bg='blue')
        self.ImbImage.pack()

        im = Image.open(r'C:\Python26\Suite\test.png')

        print im.format, im.size, im.mode

        im = ImageDraw.Draw(im)

        im = im.point((0, 0), fill="red")

        self.i = ImageTk.PhotoImage(im)
        self.ImbImage.create_image(139, 59, image=self.i)




def run():
    image_manip().mainloop()
if __name__ == "__main__":
    run()
Run Code Online (Sandbox Code Playgroud)

运行我的代码时出现以下错误:

Exception AttributeError: "PhotoImage instance has no attribute '_PhotoImage__photo'" in <bound method PhotoImage.__del__ of <PIL.ImageTk.PhotoImage instance at 0x05DF7698>> ignored
Traceback (most recent call last):
  File "<string>", line …
Run Code Online (Sandbox Code Playgroud)

python image-manipulation tkinter image-processing python-imaging-library

5
推荐指数
1
解决办法
1万
查看次数