[R] Using tcltk to display jpeg images

Philippe Grosjean phgrosjean at sciviews.org
Tue Aug 23 15:12:48 CEST 2005


Jonathan Williams wrote:
> Thank you,
> 
> I am running R 2.1.1 via Windows XP.
> 
> Sorry, you will realise how little I know about this because I
> did not know that the operating system would make a difference!

No problems. Indeed, you have to install BINARIES of the img tcl 
package. One solution is to install a Tcl/Tk distribution that includes 
already that package. ActiveTcl is the one that comes to mind 
immediatelly. Here is the procedure to use it:

- Go to http://www.activestate.com/Products/ActiveTcl/, then 'Free 
download', then download ActiveTcl 8.4.11.0 for Windows, which contains 
Img 1.3. Do NOT download ActiveTcl 8.5.XXX: it is not compatible with R!

- Install it, let's say in 'c:\Tcl'

- Create a copy of the shortcut that starts R. Rename it (for instance R 
2.1.1 - ActiveTcl).

- Right click on this shortcut and select 'Properties' in the context 
menu. Then change taget from:
"C:\Program Files\R\rw2011\bin\Rgui.exe"
to:
"C:\Program Files\R\rw2011\bin\Rgui.exe" MY_TCLTK=c:/Tcl

- Start R from this shortcut.

- Load the tcltk package and create a Tk window:
 > library(tcltk)
 > tt <- tktoplevel()

You know that you are using ActiveTcl, and not the Tcl package provided 
with R because the icon of that window is changed from a red "Tk" to the 
  brown plume that is the icon of ActiveState.

- At this point, the Img Tcl package is available to you from R. The 
rest is taken from 
http://bioinf.wehi.edu.au/~wettenhall/RTclTkExamples/showImage.html:
 > R.base.dir <- system.file()
 > setwd(paste(R.base.dir,"/../../doc/html",sep=""))
 > require(tcltk)
Loading required package: tcltk
Loading Tcl/Tk interface ... done
[1] TRUE
 > tt <- tktoplevel()
 > tclRequire("Img")
<Tcl> 1.3
 > image1 <- tclVar()
 > tkcmd("image","create","photo",image1,file="logo.jpg")
<Tcl> ::RTcl1
 > imgAsLabel <- tklabel(tt,image=image1,bg="white")
 > tkpack(imgAsLabel)
<Tcl>

You should read also the R for Windows FAQ 3.6.

Finally, when it works, there is another (and perhaps simpler) way to 
load the Img tcl package, using the Tcl version distributed with R. You 
just have to specify: addTclPath("c:/tcl/lib"). So, you can start R 
normally (using the default Tcl distributed with it), and do:
 > library(tcltk)
Loading Tcl/Tk interface ... done
 > addTclPath("c:/xtra/tcl/lib") # This is how you gain access to the 
ActiveTcl library!
 > R.base.dir <- system.file()
 > setwd(paste(R.base.dir,"/../../doc/html",sep=""))
 > tt <- tktoplevel()
 > tclRequire("Img")
<Tcl> 1.3
 > image1 <- tclVar()
 > tkcmd("image","create","photo",image1,file="logo.jpg")
<Tcl> ::RTcl1
 > imgAsLabel <- tklabel(tt,image=image1,bg="white")
 > tkpack(imgAsLabel)
<Tcl>

Note that you can relocate the /lib subdir of ActiveTcl, or only 
/lib/Img1.3 and use AddTclPath() to access it at the new location. This 
way, you don't have to install ActiveTcl on all the computers where you 
want to use Img. You just need to copy /lib/Img1.3 there and use 
AddTclPath(). However, take care of the ActiveState license that 
constrains you to download their software from their web site and to 
register. So, you can only use this method for multiple installations on 
your own computers... but not for redistribution!

Best,

Philippe Grosjean

..............................................<°}))><........
  ) ) ) ) )
( ( ( ( (    Prof. Philippe Grosjean
  ) ) ) ) )
( ( ( ( (    Numerical Ecology of Aquatic Systems
  ) ) ) ) )   Mons-Hainaut University, Pentagone (3D08)
( ( ( ( (    Academie Universitaire Wallonie-Bruxelles
  ) ) ) ) )   8, av du Champ de Mars, 7000 Mons, Belgium
( ( ( ( (
  ) ) ) ) )   phone: + 32.65.37.34.97, fax: + 32.65.37.30.54
( ( ( ( (    email: Philippe.Grosjean at umh.ac.be
  ) ) ) ) )
( ( ( ( (    web:   http://www.umh.ac.be/~econum
  ) ) ) ) )          http://www.sciviews.org
( ( ( ( (
..............................................................

> 
> Jonathan
> 
> -----Original Message-----
> From: Philippe Grosjean [mailto:phgrosjean at sciviews.org]
> Sent: 23 August 2005 10:19
> To: Jonathan Williams
> Cc: Ethz. Ch
> Subject: Re: [R] Using tcltk to display jpeg images
> 
> 
> Hello,
> 
> You have to tell us on which platform you want to install the Tcl img
> package. If it is Windows, I can help.
> Best,
> 
> Philippe
> 
> ..............................................<°}))><........
>   ) ) ) ) )
> ( ( ( ( (    Prof. Philippe Grosjean
>   ) ) ) ) )
> ( ( ( ( (    Numerical Ecology of Aquatic Systems
>   ) ) ) ) )   Mons-Hainaut University, Pentagone (3D08)
> ( ( ( ( (    Academie Universitaire Wallonie-Bruxelles
>   ) ) ) ) )   8, av du Champ de Mars, 7000 Mons, Belgium
> ( ( ( ( (
>   ) ) ) ) )   phone: + 32.65.37.34.97, fax: + 32.65.37.30.54
> ( ( ( ( (    email: Philippe.Grosjean at umh.ac.be
>   ) ) ) ) )
> ( ( ( ( (    web:   http://www.umh.ac.be/~econum
>   ) ) ) ) )          http://www.sciviews.org
> ( ( ( ( (
> ..............................................................
> 
> Jonathan Williams wrote:
> 
>>Dear R Helpers,
>>
>>Does anyone know how to use tcltk to display jpeg images? The manual says
>>that
>>one must use Tk_PhotoCreateImageFormat to register the jpeg image handler.
>>The
>>"ActiveTcl User Guide"
>>(http://support.serv.ch/lang/tcl/img/doc/img-jpeg.html)
>>says:-
>>
>>"The package img::jpeg is a sub-package of Img. It can be loaded as a part
>>of the complete
>>Img support, via package require Img, or on its own, via package require
>>img::jpeg"
>>
>>I downloaded the tkimg1.3 file from
>>http://kent.dl.sourceforge.net/sourceforge/tkimg/tkimg1.3.zip,
>>but I cannot figure out how to 'build' the files to link them to R.
>>
>>Would someone be so kind as to tell me how to do this? Better still, does
>>anyone have an R routine
>>that will do it, since I have no experience of this kind of programming.
>>
>>Thanks, in advance,
>>
>>Jonathan Williams
>>
>>______________________________________________
>>R-help at stat.math.ethz.ch mailing list
>>https://stat.ethz.ch/mailman/listinfo/r-help
>>PLEASE do read the posting guide!
> 
> http://www.R-project.org/posting-guide.html
> 
>>
> 
> 
> 
>




More information about the R-help mailing list