www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How to get a screenshot?

reply Konstantin Kutsevalov <adamasantares gmail.com> writes:
Hello everyone,

do anybody know how to get screenshot (for now in Linux only)? 
May be some library , examples?
Sep 21 2016
parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Wednesday, 21 September 2016 at 16:33:58 UTC, Konstantin 
Kutsevalov wrote:
 do anybody know how to get screenshot (for now in Linux only)? 
 May be some library , examples?
simplest might be to just call out to `shellExec("import -window root filename.png");` and it will write the file.
Sep 21 2016
parent reply Konstantin Kutsevalov <adamasantares gmail.com> writes:
On Wednesday, 21 September 2016 at 16:36:32 UTC, Adam D. Ruppe 
wrote:
 On Wednesday, 21 September 2016 at 16:33:58 UTC, Konstantin 
 Kutsevalov wrote:
 do anybody know how to get screenshot (for now in Linux only)? 
 May be some library , examples?
simplest might be to just call out to `shellExec("import -window root filename.png");` and it will write the file.
Hmm, that's good idea as fast solution. Thank you Adam.
Sep 21 2016
parent reply Antonio Corbi <acb ggmail.com> writes:
On Thursday, 22 September 2016 at 02:21:16 UTC, Konstantin 
Kutsevalov wrote:
 On Wednesday, 21 September 2016 at 16:36:32 UTC, Adam D. Ruppe 
 wrote:
 On Wednesday, 21 September 2016 at 16:33:58 UTC, Konstantin 
 Kutsevalov wrote:
 do anybody know how to get screenshot (for now in Linux 
 only)? May be some library , examples?
simplest might be to just call out to `shellExec("import -window root filename.png");` and it will write the file.
Hmm, that's good idea as fast solution. Thank you Adam.
Hi Konstantin, I've got a simple example in Vala language but it's very easy to rewrite it in D thank's to GtkD (and also thanks to Mike Wey for his work in GtkD!): // compile: valac --pkg gtk+-3.0 --pkg gdk-3.0 screenshot.vala int main (string[] args) { Gtk.init (ref args); int width, height; Gdk.Window win = Gdk.get_default_root_window(); width = win.get_width(); height = win.get_height(); Gdk.Pixbuf screenshot = Gdk.pixbuf_get_from_window(win, 0, 0, width, height); screenshot.save("screenshot.png","png"); return 0; }
Sep 22 2016
parent reply Antonio Corbi <amcb ggmail.com> writes:
On Thursday, 22 September 2016 at 07:50:07 UTC, Antonio Corbi 
wrote:
 On Thursday, 22 September 2016 at 02:21:16 UTC, Konstantin 
 Kutsevalov wrote:
 On Wednesday, 21 September 2016 at 16:36:32 UTC, Adam D. Ruppe 
 wrote:
 [...]
Hmm, that's good idea as fast solution. Thank you Adam.
Hi Konstantin, I've got a simple example in Vala language but it's very easy to rewrite it in D thank's to GtkD (and also thanks to Mike Wey for his work in GtkD!): // compile: valac --pkg gtk+-3.0 --pkg gdk-3.0 screenshot.vala int main (string[] args) { Gtk.init (ref args); int width, height; Gdk.Window win = Gdk.get_default_root_window(); width = win.get_width(); height = win.get_height(); Gdk.Pixbuf screenshot = Gdk.pixbuf_get_from_window(win, 0, 0, width, height); screenshot.save("screenshot.png","png"); return 0; }
Ok, took the time to translate it to D and created a github repo to clone. You can download and try it from: https://github.com/antoniocorbibellot/dsshot Hope It helps you. Antonio
Sep 22 2016
next sibling parent Konstantin Kutsevalov <adamasantares gmail.com> writes:
On Thursday, 22 September 2016 at 16:09:23 UTC, Antonio Corbi 
wrote:
 On Thursday, 22 September 2016 at 07:50:07 UTC, Antonio Corbi 
 wrote:
 Ok, took the time to translate it to D and created a github 
 repo to clone. You can download and try it from: 
 https://github.com/antoniocorbibellot/dsshot

 Hope It helps you.
 Antonio
Thank you Antonio, I'll try :)
Sep 22 2016
prev sibling parent reply Konstantin Kutsevalov <adamasantares gmail.com> writes:
On Thursday, 22 September 2016 at 16:09:23 UTC, Antonio Corbi 
wrote:
 Ok, took the time to translate it to D and created a github 
 repo to clone. You can download and try it from: 
 https://github.com/antoniocorbibellot/dsshot

 Hope It helps you.
 Antonio
Hey! It really works! https://github.com/antoniocorbibellot/dsshot/blob/master/source/app.d Thank you!
Sep 25 2016
parent Konstantin Kutsevalov <adamasantares gmail.com> writes:
This is example:

```
import std.stdio;
import gtk.Main;
import gtk.MainWindow;
import gtk.VBox, gtk.Label, gtk.Button;
import gdk.Gdk;
import gdk.Window;
import gdk.Pixbuf;
private import stdlib = core.stdc.stdlib : exit;

int main(string[] args)
{
	Main.init(args);
	new ApMainWindow();
	Main.run();
	return 0;
}


class ApMainWindow : MainWindow
{
	this()
	{
		super("Screen Capture");
		setTitle("Screen Capture Example");
		setDefaultSize(250, 120);
		VBox box = new VBox(false, 2);
		box.add(new Button("ScreenShot", &screenSave));
		box.add(new Button("Exit", &exitProg));
		add(box);
		showAll();
	}
	
	void screenSave(Button button)
	{
		Window win = Window.getDefaultRootWindow();
		int width = win.getWidth;
		int height = win.getHeight;
		Pixbuf screenshot = getFromWindow(win, 0, 0, width, height);
		screenshot.savev("screenshot.png", "png", null, null);
	}
	
	void exitProg(Button button)
	{
		stdlib.exit(0);
	}
}
```
Sep 25 2016