LablTk: bitmaps

XBM (X BitMap) is a format for encoding black and white images.
You certainly have many xbm files on your machine; here is one that I found in the ghostscript distribution:

#define gs_l.xbm_width 48
#define gs_l.xbm_height 48
#define gs_l.xbm_x_hot 0
#define gs_l.xbm_y_hot 0
static unsigned char gs_l.xbm_bits[] = {
0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd0, 0x00, 0x00,
0x00, 0x00, 0x00, 0xa0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x20, 0x03, 0x00,
0x00, 0x00, 0x00, 0x3e, 0x03, 0x00, 0x00, 0x00, 0xff, 0x1f, 0x07, 0x00,
0x00, 0xe0, 0xff, 0x0f, 0x07, 0x00, 0x00, 0xf8, 0xff, 0x81, 0x07, 0x00,
0x00, 0xfc, 0x1f, 0xc0, 0x0f, 0x00, 0x00, 0xfe, 0x07, 0xf0, 0x1f, 0x00,
0x00, 0xff, 0x01, 0xf8, 0x1f, 0x00, 0x00, 0xff, 0x41, 0xfc, 0x3f, 0x00,
0x80, 0xff, 0xc8, 0xfc, 0x3f, 0x00, 0x80, 0xff, 0xd8, 0xf8, 0x3f, 0x00,
0x80, 0xff, 0x98, 0xf0, 0x3f, 0x00, 0x80, 0xff, 0x10, 0xe0, 0x3f, 0x00,
0x00, 0xff, 0x01, 0xc0, 0x3f, 0x00, 0x00, 0xff, 0x81, 0x81, 0x1f, 0x00,
0x00, 0xfe, 0x83, 0x83, 0x1f, 0x00, 0x00, 0xfc, 0x0f, 0x83, 0x0f, 0x00,
0x00, 0xf8, 0x1f, 0xc3, 0x03, 0x00, 0x00, 0xe0, 0x1f, 0xe0, 0x01, 0x00,
0x00, 0xf0, 0x1f, 0x38, 0x00, 0x00, 0x00, 0xfc, 0x0f, 0x00, 0x00, 0x00,
0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x80, 0x7f, 0x00, 0x00, 0x00, 0x00,
0xc0, 0xff, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0x00, 0x00, 0x00,
0xc0, 0xff, 0xff, 0xff, 0x01, 0x00, 0xc0, 0xff, 0xff, 0xff, 0x0f, 0x00,
0x80, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0x00,
0x00, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0xfc, 0xff, 0xff, 0xff, 0x03,
0x00, 0xc0, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0xf0, 0xff, 0x03,
0xc0, 0x3f, 0x00, 0x00, 0xff, 0x03, 0xe0, 0x0f, 0x00, 0x00, 0xfe, 0x03,
0xf0, 0x07, 0xfc, 0x00, 0xfc, 0x01, 0xf0, 0x07, 0x0e, 0x00, 0xff, 0x04,
0xf0, 0x07, 0x7e, 0xe0, 0x7f, 0x02, 0xf0, 0x0f, 0xfc, 0xff, 0x1f, 0x01,
0xe0, 0x1f, 0xf0, 0xff, 0xc3, 0x00, 0xc0, 0xff, 0x00, 0x00, 0x78, 0x00,
0x80, 0xff, 0x0f, 0xf8, 0x3f, 0x00, 0x00, 0xfe, 0xff, 0xff, 0x07, 0x00,
0x00, 0xe0, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};


Save these lines into a file gs_l.xbm in your current directory if order to make the following demo work.
(This file is also included in the tarball referenced in the main web page.)
You can see that an xbm file is in fact a C include file. It specifies the the dimensions of the image, and an array of chars encoding a sequence of 0/1 bits.

Now you can use such a bitmap
in a button or a label:
A bitmap in a label.
The bitmap parameter
specifies the file containing the bitmap.
                    

The type of the bitmap parameter can be either `File of string as above, or `Predefined of string; I couldn't make out the use of the latter...



François Thomasset -- INRIA, Rocquencourt -- November 2007
Email: Francois dot Thomasset at inria dot fr