Learn R Programming

svWidgets (version 0.9-45)

Img: Manipulate image resources for the GUIs

Description

Mechanism provided here is very simple and allows for automatic loading of image resources from any package subdirectory. Currently, only Tk images loaded from GIF files are supported... but more formats could be added in the future.

Usage

imgAdd(file, type = "gif", img.type = "tkImage", update = FALSE, …)
imgDel(image)
imgGet(image)
imgNames()
imgType(image, warn = TRUE)

imgRead(dir, type = "gif", img.type = "tkImage") imgReadPackage(package, subdir = "gui", type = "gif", img.type = "tkImage")

# S3 method for guiImg print(x, …)

Arguments

file

image file from where to download the resource.

type

type of image. Currently, only 'gif' is supported.

img.type

the type of image resource to create. Currently, only 'tkImage' is supported and it is a Tcl/Tk resource.

update

do we update an already loaded image resource, or not?

image

Name of an image.

warn

do we issue a warning if the type of image is not recognized?

dir

the directory that contains one or more image files to read.

package

name of a package from where to load image resources.

subdir

subdirectory in the package where the graphical resources are stored. By default, it is the \"gui\" subdirectory.

x

an object of class 'guiImg'.

further arguments (currently not used).

Value

imgAdd() and imgGet() return the handle to the newly created image (invisibly for the imgAdd()). imgDel() returns invisibly TRUE if the resource is found and deleted, FALSE otherwise. imgNames() return the list of all images registered in .guiImgs in the SciViews:TempEnv environment. imgRead() and imgReadPackage() return invisibly the list of image files that are imported as resources.

Details

These functions care about (un)loading image resources. A list of these resources is maintained in '.guiImgs' located in the SciViews:TempEnv environment.

See Also

toolAdd

Examples

Run this code
# NOT RUN {
## These cannot be run by examples() but should be OK when pasted
## into an interactive R session with the tcltk package loaded

imgNames()
myImg <- imgAdd(system.file("gui", "logoSciViews.gif", package = "svWidgets"))
myImg  # Note that $Tk. is prepended to the name!
imgNames()
imgType(myImg)
## Place that logo in a Tk window
timg <- winAdd("timg", title = "A Tk window with image", pos ="-40+20")
labImg <- tklabel(timg, image = imgGet(myImg), bg = "white")
tkpack(labImg)
## When the image resource is deleted, it is not displayed any more (no error)
imgDel(myImg)
imgNames()
winDel("timg")
## To read all image resources at once (place this in .Lib.first())
imgReadPackage("svWidgets")
imgNames()
rm(myImg)
# }

Run the code above in your browser using DataLab