Copyright © 2008, 2009 Arndt Roger Schneider
A bitmapped computer graphic aka »image« is always encoded with a certain resolution. Images can be shrunken and zoomed to adapt them to the monitor resolution. An image deprecates in quality if it is shrunken. Otherwise, if an image is zoomed, then the additional resolution is wasted. Tcl/Tk does not have shrink or zoom capabilities of its own for images.
In the realm of Gstripes shrinking and zooming could be delegated to »pimage« from TkPath. But this cannot be seen as a solution! The dimensions, reported by hijacked controls, would be wrong, too; because these controls only work with unscaled images.
Another, and more suitable solution, is to render images in various resolutions. 72ppi for low resolution and AQUA®. And images with higher resolution for high resolution monitors. »tk scaling« can be used to determine what image set is required for the current monitor. Example 7.1, “Pimage shrink and zoom” deploys tk scaling in order to zoom or shrink an image as needed. In this scenario, the question is: what image object is to be created.
I was never very fond of loading masses of application resources, depending on some settings. In the case of Tcl/Tk and images: I usually prefer »base64« encoded images embedded in the source code. This way images are ordinary code themselves. This works fine for »Gif®« images, but not necessarily for other image types.
The »package« mechanism is better suited to select image directories. The Example 7.2, “tk scaling ” is only a demonstration.
Another, quit similar technique to Example 7.1, “Pimage shrink and zoom” is to apply a transformation on an image when displayed. Transformations are available with TkZinc 3.3.6 (Zoolbar) and TkPath (Goolbar).
The pimage transformation, as shown in Example 7.3, “TkPath Transformation” is not really usable with TkPath 0.2.4! The transformation »matrix« is evenly applied to every point of the image and thus the position is altered, too. In this case: the coordinates of the pimage are modified through »tk scaling«!
The Zoolbar provides image zooming out-of-the-box. The »vectorSize« property gets used to determine the required image size. I recommended to use a resolution independent value for »vectorSize«! The default value is set to »24p« (24 points). 24p translates into 24 pixels for tk scaling set to 1.0.
Technical solutions are under way: such as Quartz® 2D Extreme and XRender®.