displaying an Image using PIL w/o Image.show 
Author Message
 displaying an Image using PIL w/o Image.show

How do to show an Image in PIL without calling the Image.Show()
Method?  I tried to use Image.Show() but I don't have some lib that I
need.  Anyway the online docs seemed to suggest the there may be a
better way but did not say what it was.

Thanks In Advance,
Tech



Sat, 08 May 2004 11:29:58 GMT  
 displaying an Image using PIL w/o Image.show


Quote:
> How do to show an Image in PIL without calling the Image.Show()
> Method?  I tried to use Image.Show() but I don't have some lib that I
> need.  Anyway the online docs seemed to suggest the there may be a
> better way but did not say what it was.

you could display the image on a Canvas, thus showing it all via python

heres a quick hack I used to show an updated image from a {*filter*}, its
probably got all sorts of bad style, but shows an image on a canvas, and
updates it every so often

------------ code starts here ------------

from Tkinter import *
import Image, ImageTk
import {*filter*} # has methods to get images from a {*filter*}

Width, Height = 320, 240

ADDRESS="127.0.0.1"
PORT="8081"
REFRESH=500

class Camera(Frame):
    def __init__(self, parent=None, title='eHome', address=ADDRESS,
port=PORT, msecs=1000, **args):
        Frame.__init__(self, parent, args)
        self.title=title
        self.address=address
        self.port=port
        self.makeWidgets()
        self.pack(expand=YES, fill=BOTH)
        self.width=WIDTH
        self.height=HEIGHT
        self.image_store = None
        self.msecs  = msecs
        self.confirmQuit = 0
        self.drawn  = None
        self.fit = 1

    def makeWidgets(self):
        self.canvas = Canvas(self, bg='white', height=Height, width=Width)
        self.canvas.pack(side=LEFT, fill=BOTH, expand=YES)
        self.onoff = Button(self, text='Start', command=self.onStart)
        self.onoff.pack(fill=X)
        Button(self, text='Quit',  command=self.onQuit).pack(fill=X)

    def onStart(self):
        self.loop = 1
        self.onoff.config(text='Stop', command=self.onStop)
        self.canvas.config(height=self.height, width=self.width)
        self.onTimer()

    def onStop(self):
        self.loop = 0
        self.onoff.config(text='Start', command=self.onStart)

    def onQuit(self):
        self.onStop()
        self.update()
        if not self.confirmQuit:
            self.quit()
        else:
            if askyesno(self.title, 'Really quit now?'):
                self.quit()

    def onTimer(self):
        if self.loop:
            self.drawNext()
            self.after(self.msecs, self.onTimer)

    def drawNext(self):
        if self.drawn:
            self.canvas.delete(self.drawn)
        name = "campic"
        img  = self.getCamPic()
        img1=ImageTk.PhotoImage(image=img)
        self.drawn = self.canvas.create_image(2, 2, image=img1, anchor=NW)
        self.image = name, img1
        self.canvas.update()

    def getCamPic(self):
        img=ImageTk.PhotoImage(data={*filter*}.read(self.address+":"+self.port))
        return img

if __name__ == '__main__':
    root = Tk()
    root.title('CamView 1.0')
    Label(root, text="Cameras").pack()
    Camera(root, bd=3, address=ADDRESS, port=PORT, msecs=REFRESH,
relief=SUNKEN).pack()
    root.mainloop()



Sat, 08 May 2004 12:24:10 GMT  
 displaying an Image using PIL w/o Image.show

Quote:

> How do to show an Image in PIL without calling the Image.Show()
> Method?  I tried to use Image.Show() but I don't have some lib that I
> need.  Anyway the online docs seemed to suggest the there may be a
> better way but did not say what it was.

What lib does it say that you need?  What platform are you using?  What
GUI toolkit are you using, or intending to use?  (You can't display an
image without a window to display it in.)

Jeff Shannon
Technician/Programmer
Credit International



Sun, 09 May 2004 04:41:42 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. import Image vs from PIL import Image vs import PIL.Image

2. Need help with LeadTools API and displaying image in image control

3. Colormap problems (Image display, Image fromUser)

4. Image Display program for nuclear medicine images.

5. adding text to jpeg images using Python/PIL/???

6. new images from strings using PIL

7. Error message: incompatible image size when using IMAQ in image processing

8. how to display images on labview interface using matrox meteor card acquisition

9. Displaying image file using Tcl/Tk

10. Image Display using Tk

11. Help with displaying images using tcl/tk

 

 
Powered by phpBB® Forum Software