Upload image to window using xlib

I created a window class and I want to insert an image as the background of this window. File formats must be png. I used XImage of magick ++ to load the image. but don’t know how to make it as the background of my window. Any idea how to do this?

+3
source share
1 answer

Create a Pixmap with

Pixmap XCreatePixmap(display, d, width, height, depth)
      Display *display; // The display
      Drawable d;       // The Window for which to set the background

Creating a graphics context for Pixmap

GC XCreateGC(display, d, valuemask, values)

Draw an XImage in Pixmap

XPutImage(display, pixmap, gc, image, src_x, src_y, dest_x, dest_y, width, height)
        Drawable d; // The Pixmap
        XImage *image; // your XImage

Finally, set Pixmap as background background

XSetWindowBackgroundPixmap(display, w, background_pixmap)
      Display *display;
      Window w;
      Pixmap background_pixmap;

Then release all resources that you no longer need.

+3
source

All Articles