[Image-SIG] ImageTk.PhotoImage vs. Tkinter.PhotoImage
Fredrik Lundh
fredrik@pythonware.com
Wed, 29 Sep 1999 12:38:02 +0200
Les Schaffer <godzilla@netmeg.net> wrote:
> so, with code like this:
>
> ...
> self.photo = ImageTk.PhotoImage(image)
> self.canvas.create_image(0, 0, image=self.photo, anchor=NW)
> ...
>
> i want to create a new PhotoImage consisting of a zoom in on a subset
> of self.photo (i have the x,y coords of the desired zoom area in
> self.photo).
the easiest (and by far fastest) way to do this
is to keep a reference to the original PIL image,
and create a new ImageTk.PhotoImage instance
when necessary.
here's some (untested) sample code:
...
self.image = image
# display original image
self.setimage(self.image)
# display subregion
im = self.image.transform(
(512, 512), Image.EXTENT,
(12.5, 12.5, 27.5, 27.5)
)
self.setimage(im)
...
def setimage(self, image):
self.photo = ImageTk.PhotoImage(image)
self.canvas.delete("image")
self.canvas.create_image(0, 0,
image=self.photo,
anchor=NW, tag="image"
)
...
hope this helps!
</F>