21

Is it possible to get a screenshot of the entire desktop directly in Mathematica?

I am on Ubuntu running Mathematica 8. For some reason GUIScreenShot[] fails. But something like GUIScreenShot[{{0, 500}, {0, 500}}] works

It is strange that in the reference

GUIScreenShot[]

is given as an example (last one), with the caption Capture the entire screen:. But when I copy it and paste it in a notebook, it expects a parameter! (I have included the code Needs["GUIKit`"])

I get the error as shown in this image

Screenshot of the image

rm -rf
  • 88,781
  • 21
  • 293
  • 472
my account_ram
  • 2,158
  • 11
  • 25

5 Answers5

16

GUIScreenShot[] (without arguments) works perfectly fine on my Mac, although the front end syntax highlighter indicates a missing argument. As a workaround, you can explicitly give it the dimensions of your screen so that all of it is captured. Here's how you can programmatically get your screen size and use it:

Needs["GUIKit`"]
GUIScreenShot["FullScreenArea" /. Flatten@SystemInformation["Devices", "ScreenInformation"]]
rm -rf
  • 88,781
  • 21
  • 293
  • 472
8

In v11.2 you can just use CurrentScreenImage[].

user5601
  • 3,573
  • 2
  • 24
  • 56
7

A method from Kuba's answer, no GUIKit` is needed. Tested on Mathematica 10.1.

Module[{masknb, img},
       masknb = CreateWindow[{}, WindowSize -> Full, Visible -> False];
       img = MathLink`CallFrontEnd[FrontEnd`NotebookImage[masknb]];
       NotebookClose[masknb];
       img
      ]

We can even make a fairly fast screen recorder from it:

Clear[maskWindow]
maskWindow[width_, height_, leftMarg_, topMarg_] :=
    CreateWindow[{},
        WindowSize -> {width, height},
        WindowMargins -> {{leftMarg, Automatic}, {topMarg, 0}},
        Visible -> False]

Clear[screenSnapshot]
screenSnapshot[window_] := 
    MathLink`CallFrontEnd[FrontEnd`NotebookImage[window]]

screenRecord = {};
recordingFlag = True;
Column[{
        "Click to stop recording:",
        Toggler[Dynamic[recordingFlag],
            {True -> Framed["Recording"], False -> Framed["Stopped  "]}
            ]
        }]

Module[{masknb},
        masknb = maskWindow[500, 300, 300, 200];
        While[recordingFlag,
            screenRecord = Join[screenRecord, {screenSnapshot[masknb]}]
            ];
        NotebookClose[masknb];
        ];
screenRecord = Image /@ screenRecord;
ListAnimate[screenRecord]

MMA screen recorder

Silvia
  • 27,556
  • 3
  • 84
  • 164
5

Confirming @R.M's answer (WinXP, Mac OSX 10.8)

enter image description here

rm -rf
  • 88,781
  • 21
  • 293
  • 472
Dr. belisarius
  • 115,881
  • 13
  • 203
  • 453
4

Using JLink,you can do this

Needs["JLink`"];
InstallJava[];
robotclass = JavaNew["java.awt.Robot"];
LoadJavaClass["javax.imageio.ImageIO"];
LoadJavaClass["java.awt.Toolkit"];
screenSize = Toolkit`getDefaultToolkit[]@getScreenSize[];
image = robotclass@createScreenCapture[JavaNew["java.awt.Rectangle", 0, 0, screenSize@width, screenSize@height]];
ImageIO`write[image, "png",JavaNew["java.io.File", FileNameJoin[{Directory[], "test.png"}]]];
UninstallJava[]

Import["test.png"]

enter image description here

partida
  • 6,816
  • 22
  • 48