
Untitled
By: a guest on
May 4th, 2012 | syntax:
None | size: 1.16 KB | hits: 9 | expires: Never
Managing memory usage when getting many screenshots in Java
public BufferedImage getScreenShot() {
BufferedImage screenImage = null;
try {
GraphicsEnvironment ge= GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] screens=ge.getScreenDevices();
Rectangle allScreenBounds=new Rectangle();
for(GraphicsDevice screen: screens)
{
Rectangle screenbounds = screen.getDefaultConfiguration().getBounds();
allScreenBounds.width+=screenbounds.width;
allScreenBounds.height=Math.max(allScreenBounds.height, screenbounds.height);
}
Robot robot = new Robot();
screenImage = robot.createScreenCapture(allScreenBounds);
} catch (Exception ex) {
Logger.getLogger(Screen.class.getName()).log(Level.SEVERE, null, ex);
}
return screenImage;
}
while(true){
FileImageOutputStream out = new FileImageOutputStream(f);
writer.setOutput(out);
IIOImage image = new IIOImage(ImageUtils.resize(getScreenShot(), width, height),null, null);
writer.write(null, image, iwp);
writer.dispose();
}
writer.write(null, image, iwp);
image=null;