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.




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!

  • \$\begingroup\$ Sandbox: codegolf.meta.stackexchange.com/a/12564/29325 \$\endgroup\$ – sergiol Aug 24 '17 at 16:45
  • \$\begingroup\$ Sounds like a VB program \$\endgroup\$ – Stan Strum Aug 24 '17 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\$ – Jonathan Allan Aug 24 '17 at 17:04
  • 5
    \$\begingroup\$ ? A previous challenge, obviously! \$\endgroup\$ – Shaggy Aug 24 '17 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 Aug 24 '17 at 17:50

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

|improve this answer|||||
  • \$\begingroup\$ seems to me that f is not valid and should be something like (this->) GetParentWindow() Java equivalent? \$\endgroup\$ – sergiol Aug 24 '17 at 17:41
  • \$\begingroup\$ @sergiol ok I'll do that \$\endgroup\$ – geokavel Aug 24 '17 at 17:42
  • 3
    \$\begingroup\$ You'll need to fully qualify ImageIO, Robot, and File, or include import statements. \$\endgroup\$ – Jakob Aug 24 '17 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\$ – Jonathan Allan Aug 24 '17 at 17:54
  • 1
    \$\begingroup\$ @JonathanAllan deleted my comment, as I didn't read thoroughly... apologies. \$\endgroup\$ – Socratic Phoenix Aug 24 '17 at 20:20

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