Bonjour !

Je suis en train de regarder comment on peut utiliser la bibliothèque Cairo sous Linux, dans une application X11.

Pour commencer, voici un petit programme, sans fenêtre, qui permet de faire une capture d'écran. Le programme est à lancer depuis un terminal :


Il crée un fichier nommé screenshot.png, qui contient une capture de tout l'écran.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 
program Screenshot;
 
{ 
  Capture d'écran sous Linux
  https://stackoverflow.com/a/15524366
}
 
uses
  X, XLib, Cairo, CairoXLib;
 
var
  LDisplay: PDisplay;
  LScreenNum: integer;
  LWindow: TWindow;
  LVisual: PVisual;
  LWidth: integer;
  LHeight: integer;
  LSurface: pcairo_surface_t;
 
begin
  LDisplay   := XOpenDisplay(nil);
  LScreenNum := XDefaultScreen(LDisplay);
  LWindow    := XDefaultRootWindow(LDisplay);
  LVisual    := XDefaultVisual(LDisplay, LScreenNum);
  LWidth     := XDisplayWidth(LDisplay, LScreenNum);
  LHeight    := XDisplayHeight(LDisplay, LScreenNum);
 
  LSurface := cairo_xlib_surface_create(LDisplay, LWindow, LVisual, LWidth, LHeight);
  cairo_surface_write_to_png(LSurface, 'screenshot.png');
  cairo_surface_destroy(LSurface);
 
  XCloseDisplay(LDisplay);
end.