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)

// Use program "scrot" to make full-screen screenshots (on Linux); prevents the bug https://bugs.openjdk.java.net/browse/JDK-7168628
// (Bug might be fixed now, so disabling.)
static bool shootScreen_useScrot = false;

static BufferedImage shootScreen2() {
  ret shootScreen2(screenRectangle());
}

static BufferedImage shootScreen2(Rectangle area) ctex {
  ping();
  if (shootScreen_useScrot && eq(area, screenRectangle())) {
    if (!isOnPATH("scrot")) shootScreen2_fallback();
    if (shootScreen_useScrot) {
      S filename = "screenshot-" + randomID(12) + ".png";
      File f = linux_fileInRamDisk(filename);
      if (f == null) f = prepareProgramFile(filename);
      try {
        S cmd = "scrot " + bashQuote(f);
        S out = backtick(cmd);
        if (f.exists())
          ret loadPNG(f);
        shootScreen2_fallback();
      } catch e {
        print(e);
        shootScreen2_fallback();
      } finally {
        f.delete();
      }
    }
  }
  return new Robot().createScreenCapture(area);
}

static BufferedImage shootScreen2(Rect area) {
  ret shootScreen2(area.getRectangle());
}

static BufferedImage shootScreen2(int x, int y, int w, int h) {
  ret shootScreen2(new Rectangle(x, y, w, h));
}

// internal
static void shootScreen2_fallback() {
  if (shootScreen_useScrot) {
    if (isLinux()) print("Scrot failed. Reverting to internal screenshots.");
    shootScreen_useScrot = false;
  }
}

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: 285 / 309
Referenced in: [show references]