5

This is my code:

int main()
{
    Display *d = XOpenDisplay(0);
    unsigned int bitmap_width, bitmap_height;
    int x, y;
    Pixmap bitmap;

    if ( d )
    {
        Window w = XCreateWindow(d, DefaultRootWindow(d), 0, 0, 400,
                   400, 0, CopyFromParent, CopyFromParent,CopyFromParent, 0, 0);
        GC gc = XCreateGC ( d, w, 0 , NULL );

        int rc = XReadBitmapFile(d, w,
             "1.bmp",
             &bitmap_width, &bitmap_height,
             &bitmap,
             &x, &y);

        XCopyPlane(d, bitmap, w, gc,0, 0, bitmap_width, bitmap_height,0, 0, 1);
        XMapWindow(d, w);
        XFlush(d);
        sleep(10);
    }
    return 0;
}

But window is clear. I do not understand why it is not working. Where did I make mistake?

ann
  • 576
  • 1
  • 10
  • 19
user725803
  • 227
  • 2
  • 5
  • 12
  • 2
    The first two mistakes include not formatting your code correctly, and not tagging your question with the programming language you're using. – Cody Gray - on strike Jul 07 '11 at 10:45
  • why do you sleep ten seconds? – Sebastian Mach Jul 07 '11 at 11:09
  • Sorry, I'm new user and forgot about formatting. 10 seconds I sleep for viewing window – user725803 Jul 07 '11 at 12:05
  • @phresnel: The sleep is done instead of writing any event handling code, which is distracting and irrelevant to the issue at hand. It simply maps the window (draws it to the screen), the `XFlush` forces the window to be displayed (the X protocol is asynchronous), wait for 10 seconds and then (rudely) destroy the window and teardown the connection to the X server by simply exiting (at `return 0`). – mctylr Nov 28 '14 at 22:34

1 Answers1

12

Generally you create your own loader to grab the pixels out of whatever image format you need.

Then, you use XCreateImage to make an XImage, which you put, using XPutImage, on an offscreen pixmap you generate with XCreatePixmap. Once you have your pixmap, you paint it to the window with XCopyArea. You must re-copy the image on any expose events.

Dave
  • 10,964
  • 3
  • 32
  • 54