我认为使用XImage
可以满足您的需求:参见https://tronche.com/gui/x/xlib/graphics/images.html
XImage * s_image;
void init(...)
{
/* data linked to image, 4 bytes per pixel */
char *data = calloc(width * height, 4);
/* image itself */
s_image = XCreateImage(display,
DefaultVisual(display, screen),
DefaultDepth(display, screen),
ZPixmap, 0, data, width, height, 32, 0);
}
void display(...)
{
/* fill the image */
size_t offset = 0;
y = 0;
while (y < height) {
x = 0;
while (x < width) {
XPutPixel(s_image, x, y, AlphaBlend((pixels[offset++], backcolor));
x++;
}
y++;
}
/* put image on display */
XPutImage(display, drawable, cg, s_image, 0, 0, 0, 0, width, height);
XFlush(display);
}