how to save Xlib drawings into an image file? - Xwindows

This is a discussion on how to save Xlib drawings into an image file? - Xwindows ; Hi, Is there a way in X/Xlib or Motif to save the drawings on the screen (drawn by the XDrawLine etc) into image files? Thank you very much! Owen...

+ Reply to Thread
Results 1 to 8 of 8

Thread: how to save Xlib drawings into an image file?

  1. how to save Xlib drawings into an image file?

    Hi,

    Is there a way in X/Xlib or Motif to save the drawings on the screen (drawn
    by the XDrawLine etc) into image files?

    Thank you very much!

    Owen



  2. Re: how to save Xlib drawings into an image file?

    In comp.windows.x, Owen

    wrote
    on Thu, 29 Mar 2007 15:20:54 -0500
    :
    > Hi,
    >
    > Is there a way in X/Xlib or Motif to save the drawings on the screen (drawn
    > by the XDrawLine etc) into image files?
    >
    > Thank you very much!
    >
    > Owen
    >


    There's a fair number of issues here, and I'm not sure which you mean.

    [1] If you're drawing something into a Window using a
    program you've yourself written, and have sufficiently
    abstracted the problem, then you can create a Pixmap of
    the appropriate size and draw into that instead; both
    Windows and Pixmaps are Drawables.

    I'll assume you've written a function of the type

    drawAPrettyThing(Display * dpy, Drawable d, int width, int height);

    and a call such as

    Display * dpy;
    Window w;

    drawAPrettyThing(dpy, w, width, height);

    which draws into w with the requisite colors, etc., probably after
    seeing an Expose event. (Note that width and height are integers
    that should probably be picked up from a ConfigureNotify event,
    for maximum generality, although one can get away with using
    named constants after doing an XCreateSimpleWindow() with those
    constants -- for a little while.)

    You can call that code with

    Pixmap pixmap = XCreatePixmap(
    dpy, w, width, height, DefaultDepth(dpy, DefaultScreen(dpy))
    );
    drawAPrettyThing(dpy, pixmap, width, height);

    You can now splot copies of pixmap anywhere you want using XCopyArea(),
    or create an XImage using code such as:

    XImage * img = XGetImage(dpy, pixmap, 0, 0, width, height, ~0, ZPixMap);

    and then read individual pixels using XGetPixel(img, x, y)
    (slow, but not quite as slow as attempting to read pixels from
    a pixmap directly -- as pixmap is a server artifact and therefore
    each request would be a round trip; XGetPixel() by contrast
    simply peeks at the right place in img->data).

    It is possible to grab the pixels directly from the window, but if
    another window is partially or fully covering that window, you'll get
    part of that window instead.

    It is also possible to manipulate the pixels in an XImage directly
    using XPutPixel(). Such might be useful for certain effects, but
    is difficult to program.

    If you want something quick and fairly dirty, XWriteBitmapFile() takes
    a Pixmap and will generate an .xpm file. Other libraries are also
    available, such as ImageMagick. I've forgotten what Motif provides
    in this area.

    [2] There is a printing abstraction available but I've frankly not
    studied it. If you're interested, "man Xprint" or try poking around
    in www.x.org. From what I'm seeing in the manpage there's a bit of
    work involved in configuring the thing.

    [3] If you're looking for the equivalent of a Windows Metafile, the
    short answer is: there isn't one.

    HTH

    --
    #191, ewill3@earthlink.net
    Useless C++ Programming Idea #104392:
    for(int i = 0; i < 1000000; i++) sleep(0);

    --
    Posted via a free Usenet account from http://www.teranews.com


  3. Re: how to save Xlib drawings into an image file?

    Dear HTH,

    Thank you so much! That is very very helpful. One more question, is there a
    simple way to grab the pixels directly from a window? I've been through xlib
    documents, can't find it..

    Really appreciate your great help!
    Owen

    "The Ghost In The Machine" wrote in message
    news:41eud4-7j9.ln1@sirius.tg00suus7038.net...
    > In comp.windows.x, Owen
    >
    > wrote
    > on Thu, 29 Mar 2007 15:20:54 -0500
    > :
    >> Hi,
    >>
    >> Is there a way in X/Xlib or Motif to save the drawings on the screen
    >> (drawn
    >> by the XDrawLine etc) into image files?
    >>
    >> Thank you very much!
    >>
    >> Owen
    >>

    >
    > There's a fair number of issues here, and I'm not sure which you mean.
    >
    > [1] If you're drawing something into a Window using a
    > program you've yourself written, and have sufficiently
    > abstracted the problem, then you can create a Pixmap of
    > the appropriate size and draw into that instead; both
    > Windows and Pixmaps are Drawables.
    >
    > I'll assume you've written a function of the type
    >
    > drawAPrettyThing(Display * dpy, Drawable d, int width, int height);
    >
    > and a call such as
    >
    > Display * dpy;
    > Window w;
    >
    > drawAPrettyThing(dpy, w, width, height);
    >
    > which draws into w with the requisite colors, etc., probably after
    > seeing an Expose event. (Note that width and height are integers
    > that should probably be picked up from a ConfigureNotify event,
    > for maximum generality, although one can get away with using
    > named constants after doing an XCreateSimpleWindow() with those
    > constants -- for a little while.)
    >
    > You can call that code with
    >
    > Pixmap pixmap = XCreatePixmap(
    > dpy, w, width, height, DefaultDepth(dpy, DefaultScreen(dpy))
    > );
    > drawAPrettyThing(dpy, pixmap, width, height);
    >
    > You can now splot copies of pixmap anywhere you want using XCopyArea(),
    > or create an XImage using code such as:
    >
    > XImage * img = XGetImage(dpy, pixmap, 0, 0, width, height, ~0, ZPixMap);
    >
    > and then read individual pixels using XGetPixel(img, x, y)
    > (slow, but not quite as slow as attempting to read pixels from
    > a pixmap directly -- as pixmap is a server artifact and therefore
    > each request would be a round trip; XGetPixel() by contrast
    > simply peeks at the right place in img->data).
    >
    > It is possible to grab the pixels directly from the window, but if
    > another window is partially or fully covering that window, you'll get
    > part of that window instead.
    >
    > It is also possible to manipulate the pixels in an XImage directly
    > using XPutPixel(). Such might be useful for certain effects, but
    > is difficult to program.
    >
    > If you want something quick and fairly dirty, XWriteBitmapFile() takes
    > a Pixmap and will generate an .xpm file. Other libraries are also
    > available, such as ImageMagick. I've forgotten what Motif provides
    > in this area.
    >
    > [2] There is a printing abstraction available but I've frankly not
    > studied it. If you're interested, "man Xprint" or try poking around
    > in www.x.org. From what I'm seeing in the manpage there's a bit of
    > work involved in configuring the thing.
    >
    > [3] If you're looking for the equivalent of a Windows Metafile, the
    > short answer is: there isn't one.
    >
    > HTH
    >
    > --
    > #191, ewill3@earthlink.net
    > Useless C++ Programming Idea #104392:
    > for(int i = 0; i < 1000000; i++) sleep(0);
    >
    > --
    > Posted via a free Usenet account from http://www.teranews.com
    >




  4. Re: how to save Xlib drawings into an image file?

    On 2007-03-30, Owen wrote:
    > Dear HTH,
    >
    > Thank you so much! That is very very helpful. One more question, is there a
    > simple way to grab the pixels directly from a window? I've been through xlib
    > documents, can't find it..


    By chance, do you happen to mean the capability to take a
    screenshot, as is done by the Gimp, apparently by fbgrab,
    and probably by lots of other programs?

    --
    Robert Riches
    spamtrap42@verizon.net
    (Yes, that is one of my email addresses.)

  5. Re: how to save Xlib drawings into an image file?

    In comp.windows.x, Robert M. Riches Jr.

    wrote
    on Sat, 31 Mar 2007 02:20:04 GMT
    :
    > On 2007-03-30, Owen wrote:
    >> Dear HTH,
    >>
    >> Thank you so much! That is very very helpful. One more question, is there a
    >> simple way to grab the pixels directly from a window? I've been through xlib
    >> documents, can't find it..

    >
    > By chance, do you happen to mean the capability to take a
    > screenshot, as is done by the Gimp, apparently by fbgrab,
    > and probably by lots of other programs?
    >


    If he does want the entire screen, he could easily take
    the root window and grab the pixels from it. Of course
    for the casual user it's probably easiest to just use the
    PrintScrn button, which will save a file on one's desktop,
    or use Gimp's Project->Acquire menu entry.

    --
    #191, ewill3@earthlink.net
    People think that libraries are safe. They're wrong. They have ideas.
    (Also occasionally ectoplasmic slime and cute librarians.)

    --
    Posted via a free Usenet account from http://www.teranews.com


  6. Re: how to save Xlib drawings into an image file?

    In comp.windows.x, Owen

    wrote
    on Fri, 30 Mar 2007 15:28:13 -0500
    :
    > Dear HTH,


    Uh..."HTH" is an acronym for "Hope This Helps". :-)

    >
    > Thank you so much! That is very very helpful. One more question, is there a
    > simple way to grab the pixels directly from a window? I've been through xlib
    > documents, can't find it..


    As I've already mentioned below -- both Pixmaps and Windows
    are drawables; just use a Window in the XGetImage() call (keeping
    in mind that a partially covered window will yield results that may
    not be entirely to your liking, and a completely covered window will
    yield results that will definitely not be to your liking :-) ).

    Unfortunately, XWriteBitmapFile() requires a Pixmap for
    some reason, but one can easily create a PixMap, XCopyArea
    to it, and then feed to XWriteBitmapFile().

    >
    > Really appreciate your great help!
    > Owen
    >
    > "The Ghost In The Machine" wrote in message
    > news:41eud4-7j9.ln1@sirius.tg00suus7038.net...
    >> In comp.windows.x, Owen
    >>
    >> wrote
    >> on Thu, 29 Mar 2007 15:20:54 -0500
    >> :
    >>> Hi,
    >>>
    >>> Is there a way in X/Xlib or Motif to save the drawings on the screen
    >>> (drawn
    >>> by the XDrawLine etc) into image files?
    >>>
    >>> Thank you very much!
    >>>
    >>> Owen
    >>>

    >>
    >> There's a fair number of issues here, and I'm not sure which you mean.
    >>
    >> [1] If you're drawing something into a Window using a
    >> program you've yourself written, and have sufficiently
    >> abstracted the problem, then you can create a Pixmap of
    >> the appropriate size and draw into that instead; both
    >> Windows and Pixmaps are Drawables.
    >>
    >> I'll assume you've written a function of the type
    >>
    >> drawAPrettyThing(Display * dpy, Drawable d, int width, int height);
    >>
    >> and a call such as
    >>
    >> Display * dpy;
    >> Window w;
    >>
    >> drawAPrettyThing(dpy, w, width, height);
    >>
    >> which draws into w with the requisite colors, etc., probably after
    >> seeing an Expose event. (Note that width and height are integers
    >> that should probably be picked up from a ConfigureNotify event,
    >> for maximum generality, although one can get away with using
    >> named constants after doing an XCreateSimpleWindow() with those
    >> constants -- for a little while.)
    >>
    >> You can call that code with
    >>
    >> Pixmap pixmap = XCreatePixmap(
    >> dpy, w, width, height, DefaultDepth(dpy, DefaultScreen(dpy))
    >> );
    >> drawAPrettyThing(dpy, pixmap, width, height);
    >>
    >> You can now splot copies of pixmap anywhere you want using XCopyArea(),
    >> or create an XImage using code such as:
    >>
    >> XImage * img = XGetImage(dpy, pixmap, 0, 0, width, height, ~0, ZPixMap);
    >>
    >> and then read individual pixels using XGetPixel(img, x, y)
    >> (slow, but not quite as slow as attempting to read pixels from
    >> a pixmap directly -- as pixmap is a server artifact and therefore
    >> each request would be a round trip; XGetPixel() by contrast
    >> simply peeks at the right place in img->data).
    >>
    >> It is possible to grab the pixels directly from the window, but if
    >> another window is partially or fully covering that window, you'll get
    >> part of that window instead.
    >>
    >> It is also possible to manipulate the pixels in an XImage directly
    >> using XPutPixel(). Such might be useful for certain effects, but
    >> is difficult to program.
    >>
    >> If you want something quick and fairly dirty, XWriteBitmapFile() takes
    >> a Pixmap and will generate an .xpm file. Other libraries are also
    >> available, such as ImageMagick. I've forgotten what Motif provides
    >> in this area.
    >>
    >> [2] There is a printing abstraction available but I've frankly not
    >> studied it. If you're interested, "man Xprint" or try poking around
    >> in www.x.org. From what I'm seeing in the manpage there's a bit of
    >> work involved in configuring the thing.
    >>
    >> [3] If you're looking for the equivalent of a Windows Metafile, the
    >> short answer is: there isn't one.
    >>
    >> HTH
    >>
    >> --
    >> #191, ewill3@earthlink.net
    >> Useless C++ Programming Idea #104392:
    >> for(int i = 0; i < 1000000; i++) sleep(0);
    >>
    >> --
    >> Posted via a free Usenet account from http://www.teranews.com
    >>

    >
    >



    --
    #191, ewill3@earthlink.net
    People think that libraries are safe. They're wrong. They have ideas.
    (Also occasionally ectoplasmic slime and cute librarians.)

    --
    Posted via a free Usenet account from http://www.teranews.com


  7. Re: how to save Xlib drawings into an image file?

    :"| I thought HTH is something similar to HGH..

    Thanks again, your answers totally solved the problems!

    "The Ghost In The Machine" wrote in message
    news:u601e4-p5u.ln1@sirius.tg00suus7038.net...
    > In comp.windows.x, Owen
    >
    > wrote
    > on Fri, 30 Mar 2007 15:28:13 -0500
    > :
    >> Dear HTH,

    >
    > Uh..."HTH" is an acronym for "Hope This Helps". :-)
    >
    >>
    >> Thank you so much! That is very very helpful. One more question, is there
    >> a
    >> simple way to grab the pixels directly from a window? I've been through
    >> xlib
    >> documents, can't find it..

    >
    > As I've already mentioned below -- both Pixmaps and Windows
    > are drawables; just use a Window in the XGetImage() call (keeping
    > in mind that a partially covered window will yield results that may
    > not be entirely to your liking, and a completely covered window will
    > yield results that will definitely not be to your liking :-) ).
    >
    > Unfortunately, XWriteBitmapFile() requires a Pixmap for
    > some reason, but one can easily create a PixMap, XCopyArea
    > to it, and then feed to XWriteBitmapFile().
    >
    >>
    >> Really appreciate your great help!
    >> Owen
    >>
    >> "The Ghost In The Machine" wrote in
    >> message
    >> news:41eud4-7j9.ln1@sirius.tg00suus7038.net...
    >>> In comp.windows.x, Owen
    >>>
    >>> wrote
    >>> on Thu, 29 Mar 2007 15:20:54 -0500
    >>> :
    >>>> Hi,
    >>>>
    >>>> Is there a way in X/Xlib or Motif to save the drawings on the screen
    >>>> (drawn
    >>>> by the XDrawLine etc) into image files?
    >>>>
    >>>> Thank you very much!
    >>>>
    >>>> Owen
    >>>>
    >>>
    >>> There's a fair number of issues here, and I'm not sure which you mean.
    >>>
    >>> [1] If you're drawing something into a Window using a
    >>> program you've yourself written, and have sufficiently
    >>> abstracted the problem, then you can create a Pixmap of
    >>> the appropriate size and draw into that instead; both
    >>> Windows and Pixmaps are Drawables.
    >>>
    >>> I'll assume you've written a function of the type
    >>>
    >>> drawAPrettyThing(Display * dpy, Drawable d, int width, int height);
    >>>
    >>> and a call such as
    >>>
    >>> Display * dpy;
    >>> Window w;
    >>>
    >>> drawAPrettyThing(dpy, w, width, height);
    >>>
    >>> which draws into w with the requisite colors, etc., probably after
    >>> seeing an Expose event. (Note that width and height are integers
    >>> that should probably be picked up from a ConfigureNotify event,
    >>> for maximum generality, although one can get away with using
    >>> named constants after doing an XCreateSimpleWindow() with those
    >>> constants -- for a little while.)
    >>>
    >>> You can call that code with
    >>>
    >>> Pixmap pixmap = XCreatePixmap(
    >>> dpy, w, width, height, DefaultDepth(dpy, DefaultScreen(dpy))
    >>> );
    >>> drawAPrettyThing(dpy, pixmap, width, height);
    >>>
    >>> You can now splot copies of pixmap anywhere you want using XCopyArea(),
    >>> or create an XImage using code such as:
    >>>
    >>> XImage * img = XGetImage(dpy, pixmap, 0, 0, width, height, ~0, ZPixMap);
    >>>
    >>> and then read individual pixels using XGetPixel(img, x, y)
    >>> (slow, but not quite as slow as attempting to read pixels from
    >>> a pixmap directly -- as pixmap is a server artifact and therefore
    >>> each request would be a round trip; XGetPixel() by contrast
    >>> simply peeks at the right place in img->data).
    >>>
    >>> It is possible to grab the pixels directly from the window, but if
    >>> another window is partially or fully covering that window, you'll get
    >>> part of that window instead.
    >>>
    >>> It is also possible to manipulate the pixels in an XImage directly
    >>> using XPutPixel(). Such might be useful for certain effects, but
    >>> is difficult to program.
    >>>
    >>> If you want something quick and fairly dirty, XWriteBitmapFile() takes
    >>> a Pixmap and will generate an .xpm file. Other libraries are also
    >>> available, such as ImageMagick. I've forgotten what Motif provides
    >>> in this area.
    >>>
    >>> [2] There is a printing abstraction available but I've frankly not
    >>> studied it. If you're interested, "man Xprint" or try poking around
    >>> in www.x.org. From what I'm seeing in the manpage there's a bit of
    >>> work involved in configuring the thing.
    >>>
    >>> [3] If you're looking for the equivalent of a Windows Metafile, the
    >>> short answer is: there isn't one.
    >>>
    >>> HTH
    >>>
    >>> --
    >>> #191, ewill3@earthlink.net
    >>> Useless C++ Programming Idea #104392:
    >>> for(int i = 0; i < 1000000; i++) sleep(0);
    >>>
    >>> --
    >>> Posted via a free Usenet account from http://www.teranews.com
    >>>

    >>
    >>

    >
    >
    > --
    > #191, ewill3@earthlink.net
    > People think that libraries are safe. They're wrong. They have ideas.
    > (Also occasionally ectoplasmic slime and cute librarians.)
    >
    > --
    > Posted via a free Usenet account from http://www.teranews.com
    >




  8. Re: how to save Xlib drawings into an image file?

    I didn't mean that, but thanks for teaching me something new!
    Owen

    "Robert M. Riches Jr." wrote in message
    news:slrnf0rhak.3b5.rob@one.localnet...
    > On 2007-03-30, Owen wrote:
    >> Dear HTH,
    >>
    >> Thank you so much! That is very very helpful. One more question, is there
    >> a
    >> simple way to grab the pixels directly from a window? I've been through
    >> xlib
    >> documents, can't find it..

    >
    > By chance, do you happen to mean the capability to take a
    > screenshot, as is done by the Gimp, apparently by fbgrab,
    > and probably by lots of other programs?
    >
    > --
    > Robert Riches
    > spamtrap42@verizon.net
    > (Yes, that is one of my email addresses.)




+ Reply to Thread