2
\$\begingroup\$

Write the minimal code you need to take a screenshot of your application window. I am not asking for a function or program; just only a code segment.

It has obviously to be a GUI application; console applications not allowed.

Input:

None.

Output:

The valid outputs are:

  • Clipboard. Then post a screenshot of the Paste contents on a drawing program.
  • A file. Upload it somewhere and post a link to it here.
  • Inside any other window different from the window that was shoot. Post screenshot of the new window here.

As it is minimum number of characters wins!

\$\endgroup\$
20
  • \$\begingroup\$ Sandbox: codegolf.meta.stackexchange.com/a/12564/29325 \$\endgroup\$
    – sergiol
    Commented Aug 24, 2017 at 16:45
  • \$\begingroup\$ Sounds like a VB program \$\endgroup\$
    – Stan Strum
    Commented Aug 24, 2017 at 16:55
  • 1
    \$\begingroup\$ "It has obviously to be a GUI application; console applications not allowed." - may we not copy the console's GUI window itself? \$\endgroup\$ Commented Aug 24, 2017 at 17:04
  • 5
    \$\begingroup\$ ? A previous challenge, obviously! \$\endgroup\$
    – Shaggy
    Commented Aug 24, 2017 at 17:34
  • 1
    \$\begingroup\$ @DirtyDev : It seems not be a valid reason. The are lots of graphical-output challenges which many languages do not support, and frankly, who cares? \$\endgroup\$
    – sergiol
    Commented Aug 24, 2017 at 17:50

1 Answer 1

1
\$\begingroup\$

Java 8, 82 80 77 bytes

Class that extends Frame:

ImageIO.write(new Robot().createScreenCapture(bounds()),"png",new File("a"));

Regular Class 98 Bytes:

ImageIO.write(new Robot().createScreenCapture(Frame.getFrames()[0].bounds()),"png",new File("a"));

Uses deprecated bounds() method.

enter image description here

\$\endgroup\$
9
  • \$\begingroup\$ seems to me that f is not valid and should be something like (this->) GetParentWindow() Java equivalent? \$\endgroup\$
    – sergiol
    Commented Aug 24, 2017 at 17:41
  • \$\begingroup\$ @sergiol ok I'll do that \$\endgroup\$
    – geokavel
    Commented Aug 24, 2017 at 17:42
  • 3
    \$\begingroup\$ You'll need to fully qualify ImageIO, Robot, and File, or include import statements. \$\endgroup\$
    – Jakob
    Commented Aug 24, 2017 at 17:45
  • 1
    \$\begingroup\$ @sergiol If it does not need to create references then couldn't the code just be x(); where x has been defined to do all the work?! \$\endgroup\$ Commented Aug 24, 2017 at 17:54
  • 1
    \$\begingroup\$ @JonathanAllan deleted my comment, as I didn't read thoroughly... apologies. \$\endgroup\$ Commented Aug 24, 2017 at 20:20

Not the answer you're looking for? Browse other questions tagged or ask your own question.