I've created window class and i want to insert an image as a background of that window. File formats need to be png. I used XImage of magick++ to load an image. but don't know how to make its as a background of my window. Any idea how to do it?
Asked
Active
Viewed 6,263 times
1 Answers
3
Create an Pixmap using
Pixmap XCreatePixmap(display, d, width, height, depth)
Display *display; // The display
Drawable d; // The Window for which to set the background
Create a Graphics Context for the Pixmap
GC XCreateGC(display, d, valuemask, values)
Draw the XImage to the 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 the Pixmap as the window's background
XSetWindowBackgroundPixmap(display, w, background_pixmap)
Display *display;
Window w;
Pixmap background_pixmap;
Then free all resources no longer needed.

datenwolf
- 159,371
- 13
- 185
- 298
-
What should be the value mask and values for the xcreategc if Drawable d is a pixmap? – HariHaraSudhan Jun 20 '11 at 07:13
-
Can you provide me a program by drawing image using user data? – HariHaraSudhan Jun 20 '11 at 07:23
-
Another option is to use `XCopyArea` to copy one Drawable (Pixmap) onto another (Window). – marski Apr 04 '23 at 16:26
-
@marski: OP was asking about setting a window's background, and the method I outlined has the nice, beneficial side effect, that when resizing a window the background will fill it immediately (tiled). Would be nice if one could specify an origin for the background so that you could have it start some, say (-16,-16) pixels outside the window and extend for the same amount on the other side, and then update it at a low rate when resizing the window. Alas, that's not how things are. – datenwolf Apr 05 '23 at 06:28