Displaying bitmaps
To display a bitmap, the copyPlane:gc:srcX:srcY:width:height:destX:destY:plane: method is used instead of copyArea:, which is used to copy between drawables having the same depth. Like copyArea:, copyPlane: specifies the destination drawable, the source rectangle, and the destination point. It has an extra argument that specifies which plane of the source drawable to use. When displaying bitmaps, this argument should have a value of 1.
Unlike copyArea: which copies pixel values directly between the source and destination drawables, copyPlane: expands the monochrome source bitmap to color before performing the copy. Each pixel is copied as follows: If the source pixel value is 1, the foreground pixel value in the GC is combined with the destination pixel value using the GC function, and the resulting pixel value is set in the destination. If the source pixel value is 0, the background pixel value in the GC is combined with the destination pixel value using the GC function, and the resulting pixel value is set in the destination.
The following example creates a brick pattern bitmap and copies it to the root window using black as the foreground color and white as the background color:
| gc window bits bitmap |
gc := CgGC default.
window := CgWindow default.
bits := #
2r11111111
2r00000001
2r00000001
2r00000001
2r11111111
2r00010000
2r00010000
2r00010000].
bitmap := window
createBitmapFromData: bits
width: 8
height: 8.
gc
setForeground: CgWindow default blackPixel;
setBackground: CgWindow default whitePixel.
10 to: 50 by: 8 do: [:y |
10 to: 50 by: 8 do: [:x |
bitmap
copyPlane: window
gc: gc
srcX: 0
srcY: 0
width: 8
height: 8
destX: x
destY: y
plane: 1]].
bitmap freePixmap
Two additional methods, copyAreaMasked: and copyPlaneMasked:, use a mask to specify transparency.
Tip:
Note that Common Widgets provides a platform-independent way of requesting and releasing handles to shared system pixmaps in a pixmap cache using the getPixmap:foreground:background:, getPixmap:foreground:background:background:pallette:, and destroyPixmap: methods of CgScreen. The pixmaps are created from images in an image cache.
Last modified date: 01/29/2015