Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

48
LINES

< > BotCompany Repo | #1019969 // shootScreen2 with scrot (backup) - shoot as BufferedImage

JavaX fragment (include)

1  
// Use program "scrot" to make full-screen screenshots (on Linux); prevents the bug https://bugs.openjdk.java.net/browse/JDK-7168628
2  
// (Bug might be fixed now, so disabling.)
3  
static bool shootScreen_useScrot = false;
4  
5  
static BufferedImage shootScreen2() {
6  
  ret shootScreen2(screenRectangle());
7  
}
8  
9  
static BufferedImage shootScreen2(Rectangle area) ctex {
10  
  ping();
11  
  if (shootScreen_useScrot && eq(area, screenRectangle())) {
12  
    if (!isOnPATH("scrot")) shootScreen2_fallback();
13  
    if (shootScreen_useScrot) {
14  
      S filename = "screenshot-" + randomID(12) + ".png";
15  
      File f = linux_fileInRamDisk(filename);
16  
      if (f == null) f = prepareProgramFile(filename);
17  
      try {
18  
        S cmd = "scrot " + bashQuote(f);
19  
        S out = backtick(cmd);
20  
        if (f.exists())
21  
          ret loadPNG(f);
22  
        shootScreen2_fallback();
23  
      } catch e {
24  
        print(e);
25  
        shootScreen2_fallback();
26  
      } finally {
27  
        f.delete();
28  
      }
29  
    }
30  
  }
31  
  return new Robot().createScreenCapture(area);
32  
}
33  
34  
static BufferedImage shootScreen2(Rect area) {
35  
  ret shootScreen2(area.getRectangle());
36  
}
37  
38  
static BufferedImage shootScreen2(int x, int y, int w, int h) {
39  
  ret shootScreen2(new Rectangle(x, y, w, h));
40  
}
41  
42  
// internal
43  
static void shootScreen2_fallback() {
44  
  if (shootScreen_useScrot) {
45  
    if (isLinux()) print("Scrot failed. Reverting to internal screenshots.");
46  
    shootScreen_useScrot = false;
47  
  }
48  
}

Author comment

Began life as a copy of #1003731

download  show line numbers  debug dex  old transpilations   

Travelled to 9 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1019969
Snippet name: shootScreen2 with scrot (backup) - shoot as BufferedImage
Eternal ID of this version: #1019969/1
Text MD5: 483e4509532ff63940995a142db75f4d
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-12-02 15:58:28
Source code size: 1463 bytes / 48 lines
Pitched / IR pitched: No / No
Views / Downloads: 229 / 251
Referenced in: [show references]