Bitmaps can be written to files by sending the writeBitmapFile:width:height:xHot:yHot: message to the bitmap.
Tip: | The bitmap file format only supports any CgPixmap of depth one. It is an error to try to write a CgPixmap with a different depth. |
The bitmap is written in X11 bitmap file format, which looks like C source code for a structure initialization. Parameters passed to the method include the file name, the width, the height, and the hot spot coordinates within the bitmap. A hot spot is useful for cursor specifications. The write operation returns zero if successful, or an error value if unsuccessful.
| bits bitmap error | bits := #[ 2r11111111 2r00000001 2r00000001 2r00000001 2r11111111 2r00010000 2r00010000 2r00010000]. bitmap := CgWindow default createBitmapFromData: bits width: 8 height: 8.
error := bitmap writeBitmapFile: 'brick' width: 8 height: 8 xHot: 0 yHot: 0. error = 0 ifTrue: [Transcript cr; show: 'File write successful.'] ifFalse: [Transcript cr; show: 'File write error: ', error printString]. bitmap freePixmap.
The file created by this example follows:
#define brick_width 8 #define brick_height 8 #define brick_x_hot 0 #define brick_y_hot 0 static char brick_bits[] = { 0xff, 0x01, 0x01, 0x01, 0xff, 0x10, 0x10, 0x10};