Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members   Related Pages  

Displaying a CImageGrey in Tk (without TransferToPhoto)

We assume here that the library is loaded and that the operators are created. We create a TclTk proc that create a Tk image in a toplevel. The image is read from the CImageGrey one, by writing the CImageGrey on the disk (this is the simplest to do right now, because the -data option of the Tk image does only takes gif image! A pity to my opinion.)

    proc display {img} {
Write file on disk
        File PGMWrite [$img cget  -this] test.pgm
Read the image
        set res [image create photo img$img -file test.pgm]
Construct a toplevel
        toplevel .$img
        label .$img.label -text [format "pos = (%4d,%4d)     col = %4d" 0 0 0] -anchor w
        pack .$img.label
Create a canvas to put the image in
        canvas .$img.c
        .$img.c create image 1 1 -anchor nw -image $res
        pack .$img.c -fill both -expand true
and set the toplevel geometry accordingly
        set w [$img WidthGet]
        set h [$img HeightGet]
        incr w 5
        incr h 15
        wm geometry .$img [set w]x[set h]
Set some bindings to get the position and color of the pixel under mouse
        bind .$img <Motion> {  
            catch {
                set imgname [lindex [split %W .] 1]
                set color [lindex [img$imgname get %x %y] 0]
                set px %x
                set py %y
                set displaytxt "pos = (%x,%y)     col = $color"
                .$imgname.label configure -text "$displaytxt"
            }
        }
        # 
Set a binding to destroy the toplevel
        bind .$img <Control-c> {destroy .[lindex [split %W .] 1]}
Set a binding for resizing the window
        bind .$img <Configure> {
            set imgname [lindex [split %W .] 1]
        }
and end the procedure
    }

Generated at Sun May 12 19:04:30 2002 for OpenMorpho by doxygen1.2.0 written by Dimitri van Heesch, © 1997-2000