Classes of main interest are:
Smalltalk/X supports black & white, greyscale and color images with resolutions of 1, 2, 4, 8, 16, 24 and 32 bits per pixel. Independent of its depth, any image may have a photometric of greyScale, palette (i.e. uses a color lookup table) or trueColor.
When displayed, images are approximated (i.e. dithered) if the displays capabilities force this. For example, conversion of color images to dithered black & white or greyscale images is done automatically.
Images can be imported (i.e. loaded from a file) in a number of formats; among others, the common formats are supported:
Some image manipulation functionality is provided by the Image classes; for example, flip, rotate, shrink and magnify (by arbitrary factors).
Typical uses:
anImage := Image fromFile:fileName
magnifiedImage := anImage magnifiedBy:scalePoint
aView viewBackground:anImage
aTopView icon:anImage
aView displayImage:anImage
Example:
as icon:
(Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif') inspect
as view background:
|myView|
myView := StandardSystemView new.
myView extent:200@200.
myView icon:(Image fromFile:'../../goodies/bitmaps/xbmBitmaps/TicTacToe.xbm').
myView open
as drawing pens color:
|myView|
myView := View new.
myView viewBackground:((Image fromFile:'../../goodies/bitmaps/xbmBitmaps/TicTacToe.xbm') magnifiedBy:1.5).
myView open
another drawing pens color:
|myView|
myView := View new.
myView extent:200@200.
myView openAndWait.
myView paint:((Image fromFile:'../../goodies/bitmaps/xbmBitmaps/TicTacToe.xbm') magnifiedBy:0.3).
myView lineWidth:10.
myView displayLineFrom:10@10 to:100@100.
myView displayLineFrom:100@10 to:10@100.
Notice, that it may take some time to load images from a file, and
also to allocate colors and convert the image for the display device.
|myView|
myView := View new.
myView extent:400@200.
myView openAndWait.
myView paint:(Image fromFile:'../../goodies/bitmaps/xpmBitmaps/countries/argentina.xpm') on:(Color yellow).
myView font:(Font family:'helvetica' face:'bold' size:64).
myView displayOpaqueString:'hello' at:50@50.
Therefore, images are usually kept in some instance or class variable
and reused (cached). The above examples are somewhat unrealistic.
Press here for more details about:
Image
.
ImageReader is itself an abstract class; concrete subclasses care for the various
supported image formats.
Although the names of these classes imply readers, most of them also support writing
of bitmap images. For example, PNG, GIF, TIFF and BMP files can also be written.
As an example, the following code reads an image in GIF-format, and writes
it into another file in the BMP format:
if programmed as above, the format is choosen by the saveAs: method acording to the files
extension. This may not always be the correct choice.
An explicit reader should be used, if in doubt:
|img|
img := Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif'.
img saveAs:'garfield.bmp'.
|img|
img := Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif'.
WindowsIconReader save:img onFile:'garfield.foo'.
Press here for more details about:
ImageReader
.
Copyright © 1995 Claus Gittinger Development & Consulting
<cg at exept.de>