create-image, find-image, change-image, free-image

an easier way to manipulate Tk images

PACKAGE

Tk

SYNOPSIS

(create-image key create image ?options?)
(find-image key)
(change-image key create image options)
(free-image key)

DESCRIPTION

create-image is a STk procedure which simplifies Tk images creation by providing a homogeneous way to create an image, independently of its coding format. The first argument of create-image is a string which identifies the image; if an image with this key has been already loaded in memory, it will not be loaded again and create-image will return it. If no option is given, the identifying image key is taken as a file name (the file is searched using the variable *image-path*, which must contain a set of prefix pathnames to prepend to the given filename). If options are passed to the create-image procedure they must follow the convention of the options passed in image create just after the image format. If the image cannot be created, this procedure returns #f.

Hereafter is a simple usage of this procedure:

(require "image")
(require "pixmap")

(define img1 (create-image "a pixmap" :file "exit.xpm"))
(define img2 (create-image "a bitmap" :file "default.xbm"))
(define img3 (create-image "a pixmap"))
(define img4 (create-image "x.xpm"))
In this case, img3 is identical to img1 since they use the same key. Img4 is the image associated to the file "x.xpm" found according to the *image-path* varaiable.

find-image returns the image associated to the given key or #f if this image has not been loaded yet.

change-image changes the content of an image previously created with create-image. Options are the identical to create-image options.

Example:

(button '.b1 :image img1)
(button '.b2 :image img2)
(button '.b3 :image img1) ; .b3 content is identical to .b1
(pack .b1 .b2 .b3)
(change-image "a pixmap" :file "default.xbm")
After the execution of change-image, both .b1 and .b3 graphical contents are changed.

delete-image removes the image with the given key of the cache. The memory used by this image is returned to the system. See the discussion about how this image is displayed in image delete.

SEE ALSO

bitmap, image, jpeg, photo, pixmap

Back to the STk main page