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

54
LINES

< > BotCompany Repo | #1003731 // shootScreen2 - shoot as BufferedImage

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (4772L/27K).

ifdef scrot
// 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;
endifdef

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

static BufferedImage shootScreen2(Rectangle area) ctex {
  ping();
  ifdef scrot
  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();
      }
    }
  }
  endifdef
  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
ifdef scrot
static void shootScreen2_fallback() {
  if (shootScreen_useScrot) {
    if (isLinux()) print("Scrot failed. Reverting to internal screenshots.");
    shootScreen_useScrot = false;
  }
}
endifdef

Author comment

Began life as a copy of #1001347

download  show line numbers  debug dex  old transpilations   

Travelled to 18 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mowyntqkapby, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, wnsclhtenguj

No comments. add comment

Snippet ID: #1003731
Snippet name: shootScreen2 - shoot as BufferedImage
Eternal ID of this version: #1003731/16
Text MD5: 173845774765440136dd68e296d020f9
Transpilation MD5: 27066c035a196cdc25f9c52bc54a9638
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-01-16 23:54:52
Source code size: 1536 bytes / 54 lines
Pitched / IR pitched: No / No
Views / Downloads: 747 / 817
Version history: 15 change(s)
Referenced in: [show references]