← servoy magazine

[Tips] Take a Screenshot of Servoy

  • Tips

Here's a bit of code that will take a screenshot of Servoy's main window:

/*
 *	Get a screenshot of the main Servoy window
 *	Requires the images plugin to work
 *
 *	globals.myScreenShot (type: media) contains the data you can put into a column of type blob
 *
**/

//get screensize of window
var x = application.getWindowX()
var y = application.getWindowY()
var width = application.getWindowWidth()
var height = application.getWindowHeight()

//get screenshot
var screenShot = (new java.awt.Robot()).createScreenCapture(new java.awt.Rectangle(x,y,width,height))
var rawData = new java.io.ByteArrayOutputStream()
Packages.javax.imageio.ImageIO.write(screenShot,'png',rawData)
globals.myScreenShot = rawData.toByteArray()

Kind of an oddball piece of code but we have found this to be useful in user feedback systems. In one implementation, from any screen a user can trigger a feedback ticket:

[image unavailable: Picture 9] 

And fill out some typical feedback type stuff:

[image unavailable: Picture 10]

In the panel where we manage feedback tickets, a handy screenshot of where the user was at when filling out the ticket is displayed:

[image unavailable: Picture 8] 

 

Comments (2)

Patrick
Well found out! You know that there is a free plugin that does that for you already? I think the problem with the approach above is that it will not work correctly with several displays on the Mac (on Windows it will work). I just had to fix my plugin for that, update available soon.
David Workman
Ah, cool: <a href="http://www.servoy-plugins.de/plugins/screenshot/screenshot-plugin.html">screenshot plugin</a>. Some useful options for file type and output as well. Good stuff.