From: Jerry L. <jer...@ek...> - 2004-11-02 18:18:36
|
Thank you, that works a treat :) Jerry On Nov 2, 2004, at 1:09 PM, Jim Ingham wrote: > You want: > > fconfigure $fd -translation binary > > you need to stop Tcl from translating line feeds as well as from > trying to figure out the encoding & convert to UTF-8... This does > both. > > Jim > > On Nov 2, 2004, at 9:29 AM, Jerry LeVan wrote: > >> 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 >> >> >> >> ------------------------------------------------------- >> This SF.Net email is sponsored by: >> Sybase ASE Linux Express Edition - download now for FREE >> LinuxWorld Reader's Choice Award Winner for best database on Linux. >> http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click >> _______________________________________________ >> Tcl-mac mailing list >> Tc...@li... >> https://lists.sourceforge.net/lists/listinfo/tcl-mac > |