Find the answer to your Linux question:
Results 1 to 9 of 9
I want to write a simple program to capture complete desktop screenshot in pure C on linux i.e no QT or Xlib...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jul 2011
    Posts
    6

    Program to capture desktop screenshot in pure C


    I want to write a simple program to capture complete desktop screenshot in pure C on linux i.e no QT or Xlib
    Last edited by vampire36; 07-05-2011 at 12:56 PM.

  2. #2
    Just Joined!
    Join Date
    Jan 2011
    Location
    Fairfax, Virginia, USA
    Posts
    94
    Hi vampire36,
    I've done this in the past. If you don't mind using X, I'd recommend taking a look at the "X Window Dump" xwd program because its really pretty simple. I'd imagine you want to produce some kind of common image format other than an .xwd (.xwd's are really big), so that will be your trickiest part. You can use code from ImageMagik as a guide you.

    Here is the source code for xwd:
    http://cvsweb.xfree86.org/cvsweb/*ch...ype=text/plain
    Last edited by BrianMicek; 07-06-2011 at 02:26 AM. Reason: augmentation

  3. #3
    Just Joined!
    Join Date
    Jul 2011
    Posts
    6
    Well i wanted a pure C program...
    Don't want to use xwd as well !!!
    Could you suggest something else ???

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined! natediddy's Avatar
    Join Date
    Oct 2010
    Location
    Ky
    Posts
    6
    Quote Originally Posted by vampire36 View Post
    Well i wanted a pure C program...
    Don't want to use xwd as well !!!
    Could you suggest something else ???
    He's just suggesting you look at the code for xwd and/or ImageMagik so you will have some sort of idea as to where to start and what it will involve. Not to actually use the programs...

  6. #5
    Just Joined!
    Join Date
    Jul 2011
    Posts
    6
    yup I got that...
    I went through that already...
    But it uses Xlib and stuff...
    i wanted something in pure C if possible...

  7. #6
    Just Joined!
    Join Date
    Jul 2011
    Posts
    6
    Quote Originally Posted by BrianMicek View Post
    Hi vampire36,
    I've done this in the past. If you don't mind using X, I'd recommend taking a look at the "X Window Dump" xwd program because its really pretty simple. I'd imagine you want to produce some kind of common image format other than an .xwd (.xwd's are really big), so that will be your trickiest part. You can use code from ImageMagik as a guide you.
    the code of xdw seems pretty complex...
    could you just make a simple code which would capture desktop screenshot...
    maybe using xlib...cos i find no other solution...

  8. #7
    Just Joined!
    Join Date
    Mar 2011
    Posts
    4
    Even pure C would have to interact with the xlib resources to be aware of existing screens running on desktop. Seems like a lot of "recreating the wheel" to write all in C, unless your application requires it.
    I prefer ImageMagik you can simply add code like this in C to use:
    Code:
    %%system("import -window root root.jpeg")
    xwd is a more likely already installed on more systems.
    Code:
    %%system(xwd -root -out test.xwd)
    However you will still need to format the .xwd to your preferred format.

  9. #8
    Just Joined!
    Join Date
    Jul 2011
    Posts
    6
    Na that would fork a new process and want to avoid that...
    so no commandline would work...
    even xlib would be fine...
    i wanna capture the image and dump in raw format into a file...
    any suggestion ???

  10. #9
    Just Joined!
    Join Date
    Apr 2011
    Posts
    19

    XGetImage

    You probably want to use XGetImage as the X call. To grab stuff off the xcreenm you have to use X, X is the screen I'd suggest looking at the xwd stuff to figure out how to open the display and the associated setup. The bible on this stuff is the OReilly books by Adrian Nye vol's 1 & 2, The Xlib Programming manual & X Reference manual. Worthwhile investment if you are going to do much in X.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •