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