Displaying images
The putDeviceIndependentImage:image:srcRect:destRect: method of CgDrawable is used to display images. As with all drawing operations, the first argument is a CgGC specifying the drawing attributes. The next argument is the image to display. The last two arguments are a source rectangle, specifying the area of the image to display, and a destination rectangle, specifying the area of the drawable in which to display the source area. If the source and destination rectangles do not have the same extent, the source area of the image is stretched or shrunk to fit in the destination area. The image can be flipped by specifying a negative width or height in the destination or source rectangles.
The following code displays the image created in the previous example, stretched by a factor of two. To ensure that the required colors are available in the video hardware, the image's palette is first selected in the window of the shell widget. This code assumes that the shell method answers the shell widget and that the drawable method answers the window of the drawing area.
self shell window setPalette: image palette.
gc := self drawable
createGC: None
values: CgGCValues new.
self drawable
putDeviceIndependentImage: gc
image: image
srcRect: (0@0 extent: image extent)
destRect: (20@20 extent: image extent * 2).
gc freeGC
Last modified date: 04/18/2020