Hello Community,

I am developing a project using Xlib with C++. What I am focused on doing now, after successfully implemented some basic operations, is to load a PNG image from disk into the window. I've been searching the web and I can't really find something that could explain how can i load an image from the disk into my window. I've seen how to load a .xbm file, but unfortunately, converting png to xbm loses A LOT of quality on image. The other option I've thought about, was to convert png to xpm (X Pixmap). However I don't know either how can I load a XPM from disk into my project window.

Does anyone have a clue on how to load a PNG or XPM image into the window?

I have tried using:

Code:
 Pixmap pix = XCreatePixmap(display, RootWindow(display, screen), 800, 600, DefaultDepth(display, screen));
    pix = XCreateBitmapFromData (display, RootWindow(display, screen), (char*)img_bits, 800, 600);
Where img_bits is a char array with the RGB values of each pixel of the image, which I got through running some functions of the libpng. Unfortunately I get the error X Error of failed request: BadMatch (invalid parameter attributes)
Major opcode of failed request: 62 (X_CopyArea)
Serial number of failed request: 19
Current serial number in output stream: 19

Then I decided to try:
Code:
Pixmap pix = XCreatePixmap(display, RootWindow(display, screen), 800, 600, DefaultDepth(display, screen));
 Visual *visual;
   XImage* ximg = XCreateImage(display, visual, 24, XYBitmap, 0, (char*)img_bits, 800 , 600, 32, 32);
XPutImage(display, window, DefaultGC(display, screen), ximg, 0, 0, 0, 0, 800, 600);
Here I get a Segmentation fault, as after XCreateImage it returns a 0/NULL

Thank you very much in advance.