XReadBitmapFile, XReadBitmapFileData, XWriteBitmapFile, XCreatePixmapFromBitmapData, XCreateBitmapFromData - manipulate bitmaps


int XReadBitmapFile(Display *display, Drawable d, char *filename, unsigned int *width_return, unsigned int *height_return, Pixmap *bitmap_return, int *x_hot_return, int *y_hot_return); int XReadBitmapFileData(char *filename, unsigned int *width_return, unsigned int *height_return, unsigned char *data_return, int *x_hot_return, int *y_hot_return); int XWriteBitmapFile(Display *display, char *filename, Pixmap bitmap, unsigned int width, unsigned int height, int x_hot, int y_hot); Pixmap XCreatePixmapFromBitmapData(Display *display, Drawable d, char *data, unsigned int width, unsigned int height, unsigned long fg, unsigned long bg, unsigned int depth); Pixmap XCreateBitmapFromData(Display *display, Drawable d, char *data, unsigned int width, unsigned int height);


bitmap 1i Specifies the bitmap.

bitmap_return 1i Returns the bitmap that is created.

d 1i Specifies the drawable\*(Dr.

data 1i Specifies the data in bitmap format.

data 1i Specifies the location of the bitmap data.

data_return 1i Returns the bitmap data.

depth 1i Specifies the depth of the pixmap.

display 1i Specifies the connection to the X server.

fg 1i

bg 1i Specify the foreground and background pixel values to use.

filename 1i Specifies the file name to use. The format of the file name is operating-system dependent.

width 1i

height 1i Specify the width and height.

width_return 1i

height_return 1i Return the width and height values of the read in bitmap file.

x_hot 1i

y_hot 1i Specify where to place the hotspot coordinates (or -1,-1 if none are present) in the file.

x_hot_return 1i

y_hot_return 1i Return the hotspot coordinates.


The .ZN XReadBitmapFile function reads in a file containing a bitmap. The file is parsed in the encoding of the current locale. The ability to read other than the standard format is implementation-dependent. If the file cannot be opened, .ZN XReadBitmapFile returns .ZN BitmapOpenFailed . If the file can be opened but does not contain valid bitmap data, it returns .ZN BitmapFileInvalid . If insufficient working storage is allocated, it returns .ZN BitmapNoMemory . If the file is readable and valid, it returns .ZN BitmapSuccess .

.ZN XReadBitmapFile returns the bitmap's height and width, as read from the file, to width_return and height_return. It then creates a pixmap of the appropriate size, reads the bitmap data from the file into the pixmap, and assigns the pixmap to the caller's variable bitmap. The caller must free the bitmap using .ZN XFreePixmap when finished. If name_x_hot and name_y_hot exist, .ZN XReadBitmapFile returns them to x_hot_return and y_hot_return; otherwise, it returns -1,-1.

.ZN XReadBitmapFile can generate .ZN BadAlloc and .ZN BadDrawable errors.

The .ZN XReadBitmapFileData function reads in a file containing a bitmap, in the same manner as .ZN XReadBitmapFile , but returns the data directly rather than creating a pixmap in the server. The bitmap data is returned in data_return; the client must free this storage when finished with it by calling .ZN XFree . The status and other return values are the same as for .ZN XReadBitmapFile .

The .ZN XWriteBitmapFile function writes a bitmap out to a file in the X Version 11 format. The name used in the output file is derived from the file name by deleting the directory prefix. The file is written in the encoding of the current locale. If the file cannot be opened for writing, it returns .ZN BitmapOpenFailed . If insufficient memory is allocated, .ZN XWriteBitmapFile returns .ZN BitmapNoMemory ; otherwise, on no error, it returns .ZN BitmapSuccess . If x_hot and y_hot are not -1, -1, .ZN XWriteBitmapFile writes them out as the hotspot coordinates for the bitmap.

.ZN XWriteBitmapFile can generate .ZN BadDrawable and .ZN BadMatch errors.

The .ZN XCreatePixmapFromBitmapData function creates a pixmap of the given depth and then does a bitmap-format .ZN XPutImage of the data into it. The depth must be supported by the screen of the specified drawable, or a .ZN BadMatch error results.

.ZN XCreatePixmapFromBitmapData can generate .ZN BadAlloc and .ZN BadMatch errors.

The .ZN XCreateBitmapFromData function allows you to include in your C program (using .ZN #include ) a bitmap file that was written out by .ZN XWriteBitmapFile (X version 11 format only) without reading in the bitmap file. The following example creates a gray bitmap:

#include "gray.bitmap"

Pixmap bitmap; bitmap = XCreateBitmapFromData(display, window, gray_bits, gray_width, gray_height); .De

If insufficient working storage was allocated, .ZN XCreateBitmapFromData returns .ZN None . It is your responsibility to free the bitmap using .ZN XFreePixmap when finished.

.ZN XCreateBitmapFromData can generate a .ZN BadAlloc error.


  • .ZN BadAlloc
     The server failed to allocate the requested resource or server memory.
  • .ZN BadDrawable
     A value for a Drawable argument does not name a defined Window or Pixmap.
  • .ZN BadMatch
     An .ZN InputOnly window is used as a Drawable.


XCreatePixmap(3), XPutImage(3)