XReadBitmapFile(3)
okay bestie, welcome to XReadBitmapFile(3) from the XLIB FUNCTIONS shelf. This is the bitmap-manipulation page: reading, writing, and creating pixmaps from bitmap data. Vibe check: very Xlib, very useful, and yes weβre keeping every detail π .
π NAME π
XReadBitmapFile, XReadBitmapFileData, XWriteBitmapFile, XCreatePixmapFromBitmapData, XCreateBitmapFromData β literally here to manipulate bitmaps π
β¨ SYNTAX β¨
int XReadBitmapFile(Display *display, Drawable d, _Xconst char
*filename, unsigned int *width_return, unsigned int
*height_return, Pixmap *bitmap_return, int *x_hot_return, int
*y_hot_return);
int XReadBitmapFileData(_Xconst 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, _Xconst 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, _Xconst char
*data, unsigned int width, unsigned int height);
π«Ά ARGUMENTS π«Ά
bitmapβ Specifies the bitmap.bitmap_returnβ Returns the bitmap that is created.dβ Specifies the drawable that indicates the screen.dataβ Specifies the data in bitmap format.dataβ Specifies the location of the bitmap data. yes,datashows up twice in the original list, and both meanings are here πdata_returnβ Returns the bitmap data.depthβ Specifies the depth of the pixmap.displayβ Specifies the connection to the X server.fg,bgβ Specify the foreground and background pixel values to use.filenameβ Specifies the file name to use. The format of the file name is operating-system dependent.width,heightβ Specify the width and height.width_return,height_returnβ Return the width and height values of the read in bitmap file.x_hot,y_hotβ Specify where to place the hotspot coordinates (or-1,-1if none are present) in the file.x_hot_return,y_hot_returnβ Return the hotspot coordinates.
π DESCRIPTION π
XReadBitmapFile π
Okay so XReadBitmapFile 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 β iykyk, donβt @ me.
Status tea: if the file cannot be opened, it returns BitmapOpenFailed. If the file can be opened but does not contain valid bitmap data, it returns BitmapFileInvalid. If insufficient working storage is allocated, it returns BitmapNoMemory. If the file is readable and valid, it returns BitmapSuccess. Slay.
Then it returns the bitmapβs height and width, as read from the file, to width_return and height_return. It 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 XFreePixmap when finished β thatβs not optional, bestie. If name_x_hot and name_y_hot exist, it returns them to x_hot_return and y_hot_return; otherwise, it returns -1,-1.
XReadBitmapFile can generate BadAlloc and BadDrawable errors.
XReadBitmapFileData π¦
The XReadBitmapFileData function reads in a file containing a bitmap, in the same manner as 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 XFree. The status and other return values are the same as for XReadBitmapFile. No server pixmap, just data β main character energy.
XWriteBitmapFile πΈ
XWriteBitmapFile 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 BitmapOpenFailed. If insufficient memory is allocated, it returns BitmapNoMemory; otherwise, on no error, it returns BitmapSuccess. If x_hot and y_hot are not -1, -1, it writes them out as the hotspot coordinates for the bitmap.
XWriteBitmapFile can generate BadDrawable and BadMatch errors.
XCreatePixmapFromBitmapData π₯
XCreatePixmapFromBitmapData creates a pixmap of the given depth and then does a bitmap-format XPutImage of the data into it. The depth must be supported by the screen of the specified drawable, or a BadMatch error results. Thatβs the rules, fr fr.
XCreatePixmapFromBitmapData can generate BadAlloc and BadMatch errors.
XCreateBitmapFromData π§
XCreateBitmapFromData lets you include in your C program (using #include) a bitmap file that was written out by 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);
If insufficient working storage was allocated, XCreateBitmapFromData returns None. It is your responsibility to free the bitmap using XFreePixmap when finished.
XCreateBitmapFromData can generate a BadAlloc error.
π DIAGNOSTICS π
BadAllocβ The server failed to allocate the requested resource or server memory.BadDrawableβ A value for aDrawableargument does not name a definedWindoworPixmap.BadMatchβ AnInputOnlywindow is used as aDrawable.
π SEE ALSO π
XCreatePixmap(3),XPutImage(3)Xlib - C Language X Interface
signed, sealed, delivered by X Version 11 / libX11 1.8.14 β the original footer is XReadBitmapFile(3), and it didnβt give us a date, so no invented calendar tea here π
β¨
π¦ where this page comes from
- alpine 3.24: libx11-doc 1.8.14-r0 Β· X11
- arch rolling: libx11 1.8.14-1 Β· MIT AND X11
- nixos 26.05: libx11 1.8.14
- nixpkgs unstable: libx11 1.8.14
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms