Advertisement
jckuri

screen-capture-ubuntu.c

Jul 1st, 2014
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.15 KB | None | 0 0
  1. // screen-capture-ubuntu.c
  2. // gcc screen-capture-ubuntu.c -o screen-capture-ubuntu `pkg-config --libs --cflags gtk+-2.0`
  3. // http://www.bravegnu.org/gtktext/x498.html
  4. // http://www.cs.dartmouth.edu/~campbell/cs50/project/gtk.html
  5. // http://stackoverflow.com/questions/3124229/taking-a-screenshot-with-c-gtk
  6. // http://stackoverflow.com/questions/11963561/screen-capture-in-haskell?lq=1
  7. // http://askubuntu.com/questions/5847/how-to-resolve-gdk-pixbuf-gdk-pixbuf-h-no-such-file-or-directory
  8. // https://developer.gnome.org/gdk-pixbuf/unstable/gdk-pixbuf-The-GdkPixbuf-Structure.html
  9. // https://developer.gnome.org/gdk3/stable/gdk3-Windows.html#GdkWindow-struct
  10. // http://stackoverflow.com/questions/126141/how-do-you-find-out-which-version-of-gtk-is-installed-on-ubuntu
  11. // http://ubuntuforums.org/showthread.php?t=536115
  12. // sudo apt-get install libgdk-pixbuf2.0-dev
  13. // sudo apt-get install libgtk2.0-dev
  14. // pkg-config --cflags gdk-pixbuf-2.0
  15. // pkg-config --cflags gtk+-2.0
  16. // dpkg --list | grep gdk
  17.  
  18. #include <gtk/gtk.h>
  19. #include <gdk-pixbuf/gdk-pixbuf.h>
  20.  
  21. GdkPixbuf * get_screenshot(){
  22.  GdkPixbuf *screenshot;
  23.  GdkWindow *root_window;
  24.  gint x_orig, y_orig;
  25.  gint width, height;
  26.  root_window = gdk_get_default_root_window ();
  27.  gdk_drawable_get_size (root_window, &width, &height);      
  28.  gdk_window_get_origin (root_window, &x_orig, &y_orig);
  29.  screenshot = gdk_pixbuf_get_from_drawable (NULL,root_window,NULL,x_orig,y_orig,0,0,width,height);
  30.  return screenshot;
  31. }
  32.  
  33. void addScreenCapture(GtkWidget *window) {
  34.  GtkWidget *image;
  35.  GdkPixbuf *pixbuf;
  36.  pixbuf = get_screenshot();
  37.  image = gtk_image_new_from_pixbuf(pixbuf);
  38.  gtk_container_add (GTK_CONTAINER (window),image);
  39. }
  40.  
  41. int main (int argc, char *argv[]) {
  42.  GtkWidget *window;
  43.  /* Initialize the GTK+ and all of its supporting libraries. */
  44.  gtk_init (&argc, &argv);
  45.  /* Create a new window, give it a title and display it to the user. */
  46.  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  47.  gtk_window_set_title (GTK_WINDOW (window), "Hello World");
  48.  //gtk_widget_show (window);
  49.  addScreenCapture(window);
  50.  gtk_widget_show_all (window);
  51.  /* Hand control over to the main loop. */
  52.  gtk_main ();
  53.  return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement