16.9 Manipulating Bitmaps

Xlib provides functions that you can use to read a bitmap from a file, save a bitmap to a file, or create a bitmap. This section describes those functions that transfer bitmaps to and from the client's file system, thus allowing their reuse in a later connection (for example, from an entirely different client or to a different display or server).

The X version 11 bitmap file format is:


#define name_width width
#define name_height height
#define name_x_hot x
#define name_y_hot y
static unsigned char name_bits[] = { 0xNN,... }

The lines for the variables ending with _x_hot and _y_hot suffixes are optional because they are present only if a hotspot has been defined for this bitmap. The lines for the other variables are required. The word ``unsigned'' is optional; that is, the type of the _bits array can be ``char'' or ``unsigned char''. The _bits array must be large enough to contain the size bitmap. The bitmap unit is eight.

To read a bitmap from a file and store it in a pixmap, use XReadBitmapFile().

To read a bitmap from a file and return it as data, use XReadBitmapFileData().

To write out a bitmap from a pixmap to a file, use XWriteBitmapFile().

To create a pixmap and then store bitmap-format data into it, use XCreatePixmapFromBitmapData().

To include a bitmap written out by XWriteBitmapFile() in a program directly, as opposed to reading it in every time at run time, use XCreateBitmapFromData().

Next: Using the Context Manager

Christophe Tronche, ch@tronche.com