From: Jerry L. <jer...@ek...> - 2004-11-02 17:29:53
|
Hi, I am trying to understand some aspects of Tk on my Mac :) The project at hand is to read a jpg file into a string, then pass the ***string*** to a proc that will display the image. In the code below if I suppress the fconfigure statement then images are not recognized when the -data option is used. (I get a variety of bad format errors....) adding the fconfigure statement improves the situation, but the colors are badly scrambled, ( the program does not die with a bad format error). I suspect the string passed is somehow mangled during the read... Is there any way to fix the problem? Thanks, Jerry *********************************** #!/usr/bin/wish package require Img proc Scrolled_Canvas { c args } { frame $c eval {canvas $c.canvas \ -xscrollcommand [list $c.xscroll set] \ -yscrollcommand [list $c.yscroll set] \ -highlightthickness 0 \ -borderwidth 0} $args scrollbar $c.xscroll -orient horizontal \ -command [list $c.canvas xview] scrollbar $c.yscroll -orient vertical \ -command [list $c.canvas yview] grid $c.canvas $c.yscroll -sticky news grid $c.xscroll -sticky ew grid rowconfigure $c 0 -weight 1 grid columnconfigure $c 0 -weight 1 return $c.canvas } proc showAsImage { rawStr } { toplevel .asImage wm title .asImage "Image Viewer" set theView [Scrolled_Canvas .asImage.c -width 640 \ -height 480 \ -scrollregion {0 0 1000 1400} ] button .asImage.exit -text "Exit Image Window" -command {destroy .asImage} pack .asImage.exit -side bottom pack .asImage.c -side bottom -fill both -expand yes set thePhoto [image create photo -data $rawStr ] $theView create image 0 0 -image $thePhoto -anchor nw -tag myPic } # main code start here... wm withdraw . if { [catch {open /Users/jerry/desktop/Jerry.jpg} fd ] } { puts $fd exit } fconfigure $fd -encoding binary set str [read $fd] close $fd showAsImage $str |