Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing PIL's ImageDraw Module
    primarykey
    data
    text
    <p>I'm trying to do individual pixel manipulation using PIL's ImageDraw Module. The code bellow is supposed to create Tkinter canvas widget. Then open an image, change one pixel's color to red, then embed the image in the canvas widget. However, it doesn't seem to be working.</p> <p>My Code:</p> <pre><code>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() </code></pre> <p>I get the following error upon running my code:</p> <pre><code>Exception AttributeError: "PhotoImage instance has no attribute '_PhotoImage__photo'" in &lt;bound method PhotoImage.__del__ of &lt;PIL.ImageTk.PhotoImage instance at 0x05DF7698&gt;&gt; ignored Traceback (most recent call last): File "&lt;string&gt;", line 245, in run_nodebug File "C:\Python26\Suite\test_image.py", line 30, in &lt;module&gt; run() File "C:\Python26\Suite\test_image.py", line 28, in run image_manip().mainloop() File "C:\Python26\Suite\test_image.py", line 20, in __init__ self.i = ImageTk.PhotoImage(im) File "C:\Python26\lib\site-packages\PIL\ImageTk.py", line 109, in __init__ mode = Image.getmodebase(mode) File "C:\Python26\lib\site-packages\PIL\Image.py", line 245, in getmodebase return ImageMode.getmode(mode).basemode File "C:\Python26\lib\site-packages\PIL\ImageMode.py", line 50, in getmode return _modes[mode] KeyError: None </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload