Have you ever, thought up for taking the screenshot of your desktop in Servoy? Just like the Print screen button of Windows keyboard. Here is a quick Tip to show how you can do that in Servoy application.
Here is a Servoy method I have written which takes screenshot of your desktop and returns the byte array of the specified image format.
The variable “desktopImage” contains the byte array of the screenshot of your Screen of PNG File format.
Update – This method works in both Windows and mac OSX in Rich and Web Clients.
function takeScreenShot()
{
/*
method name : takeScreenShot
usage: takeScreenShot(imageFormat);
input: imageFormat: text representing the image mime type.
Ex. “png”, “jpg”, “jpeg” etc.
output: The script will take a screen shot of your desktop
and returns byte array of the specified image format.
note:
Change history:
04/14/09 Arup Ranjan Sahoo Created method
*********************************************************************/
//Get the Image Format
var imageFormat = arguments[0];
//Get the Desktop Screen Size
var screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
var screenRect = new java.awt.Rectangle(0, 0
, screenSize.width, screenSize.height);
//Capture the Screen as a Buffered Image
var screenImage = new java.awt.Robot().createScreenCapture(screenRect);
//Convert the Buffered Image to Byte Array
var baos = new java.io.ByteArrayOutputStream();
Packages.javax.imageio.ImageIO.write(screenImage
, imageFormat, baos);
return baos.toByteArray();
}
How to Use
Usage of the above method is summarized below.
Method Syntax:
takeScreenShot(imageFormat);
imageFormat: text representing the image mime type.
Ex. “png”, “jpg”, “jpeg” etc.
Usage:
//Getting the Screenshot
var desktopImage = takeScreenShot(“png”);
Now, the variable “desktopImage” contains the byte array of the screenshot of your Screen of PNG File format.