get a screenshot as servoy function?

Find out how to get things done with Servoy. Post how YOU get things done with Servoy

get a screenshot as servoy function?

Postby tgs » Fri Dec 16, 2011 11:55 am

I would like to get a screenshot by executing a servoy function.
I couldn't find a plugin or anything else to get this running, but I found a pure java code for that:
Code: Select all
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.io.File;

...

public void captureScreen(String fileName) throws Exception {

   Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
   Rectangle screenRectangle = new Rectangle(screenSize);
   Robot robot = new Robot();
   BufferedImage image = robot.createScreenCapture(screenRectangle);
   ImageIO.write(image, "png", new File(fileName));

}

Is it possible to execute a pur java code from a servoy method, or do I have to create a plugin for that?

Regards
Thomas Schnaus
SAN Developer
yomotec GmbH
User avatar
tgs
 
Posts: 886
Joined: Wed Oct 04, 2006 12:05 pm
Location: Germany

Re: get a screenshot as servoy function?

Postby ngervasi » Fri Dec 16, 2011 12:48 pm

No need to reinvent the wheel: http://www.servoy-plugins.de/plugins/screenshot/screenshot-plugin.html
Anyway executing java code in a servoy method is possible.
Nicola Gervasi
sintpro.com
SAN Partner
ngervasi
 
Posts: 1485
Joined: Tue Dec 21, 2004 12:47 pm
Location: Arezzo, Italy

Re: get a screenshot as servoy function?

Postby tgs » Fri Dec 16, 2011 1:11 pm

Thank you Nicola!

ngervasi wrote:Anyway executing java code in a servoy method is possible.


How do I get java code in a servoy method running?

Regards
Thomas Schnaus
SAN Developer
yomotec GmbH
User avatar
tgs
 
Posts: 886
Joined: Wed Oct 04, 2006 12:05 pm
Location: Germany

Re: get a screenshot as servoy function?

Postby ngervasi » Fri Dec 16, 2011 1:27 pm

Just write it in the method, example:

Code: Select all
var fr = new Packages.java.io.FileReader('/tmp/xyz.log');
var br = new Packages.java.io.BufferedReader(fr);
global.my3lines += br.readLine();
global.my3lines += br.readLine();
global.my3lines += br.readLine();
br.close();//do NOT forget this close! to prevent mem leaks, even better to use try/finally here
Nicola Gervasi
sintpro.com
SAN Partner
ngervasi
 
Posts: 1485
Joined: Tue Dec 21, 2004 12:47 pm
Location: Arezzo, Italy

Re: get a screenshot as servoy function?

Postby tgs » Tue Dec 20, 2011 10:43 am

Hi Nicola,

sorry for the delay. The sreenshot function by Patrick's plugin is working well. Now I will try executing Java in a Servoy method like your example. Hope I get it working...

Merry Christmas!
Thomas Schnaus
SAN Developer
yomotec GmbH
User avatar
tgs
 
Posts: 886
Joined: Wed Oct 04, 2006 12:05 pm
Location: Germany

Re: get a screenshot as servoy function?

Postby sovanm » Tue Dec 20, 2011 11:13 am

Hi Thomas,

I also tried to execute java codes from servoy method but didn't succeed ... :(
It would be nice if you could share a sample method to execute the same..


Sovan
sovanm
 
Posts: 99
Joined: Fri Oct 28, 2011 1:55 pm
Location: Bhubaneswar, India

Re: get a screenshot as servoy function?

Postby Kahuna » Tue Dec 20, 2011 11:38 am

sovanm wrote:Hi Thomas,

I also tried to execute java codes from servoy method but didn't succeed ... :(
It would be nice if you could share a sample method to execute the same..


Sovan
We use the screenshot code from Arup (was with Mindfire but not sure now)

To call it:
Code: Select all
function onTakeScreenSnapshot(event)
{
   var desktopImage = globals.takeScreenShot("png");
   var saveFileName = plugins.file.showFileSaveDialog('RISCm_screen_dump.png','Save Image')
   var createdFile = plugins.file.writeFile(saveFileName,desktopImage)
   if(!createdFile)
   {   globals.DIALOGS.showErrorDialog('Flie Save Error','Your File Was NOT Saved', 'OK')
   }
   else {globals.DIALOGS.showInfoDialog('Flie Saved','Your File Was Saved to '+saveFileName, 'OK')}
}

The function:
Code: Select all
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.
            * IRJC Modified this to grab just the current Servoy Window.
            note:
                Change history:
                04/14/09             Arup Ranjan Sahoo            Created method
*********************************************************************/
         //Get the Image Format
         var imageFormat = arguments[0];
         //Get the Desktop Screen Size
         screenWidth = application.getWindowWidth()
         screenHeight = application.getWindowHeight()
         screenX = application.getWindowX()
         screenY =application.getWindowY()
         var screenRect = new java.awt.Rectangle(screenX, screenY, screenWidth, screenHeight);
         //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();
}


HTH

Ian
(Servoy Version: 6.0.7 Win XP / 7 - SQL Server 2008 R2)
Ian Cordingley (Kahuna)
Kahuna
 
Posts: 1235
Joined: Thu Oct 26, 2006 1:39 am
Location: 1/2 NE UK 1/2 Olvera Spain

Re: get a screenshot as servoy function?

Postby sovanm » Tue Dec 20, 2011 1:28 pm

Thanks Ian for the reply.

That Helped....



Sovan
sovanm
 
Posts: 99
Joined: Fri Oct 28, 2011 1:55 pm
Location: Bhubaneswar, India


Return to How To

Who is online

Users browsing this forum: No registered users and 7 guests