Puneet Kalra - www.Puneetk.com

home | pwing | pikk

biography | facebook | contact

“Developing real time human a like robotics system with extra ordinary artificial intelligence, Not only artificial intelligence. A system that can learn new things itself” ~Puneet Kalra

< SUBSCRIBE >VIA FACEBOOK
FAVOURITES
Videos »
GET INSPIRED

Posts Tagged ‘Screen Shot’

Screen Shot Using Java

June 29th, 2009

Hello all,

I’m back ! Hope you all enjoyed Christmas. Today, I will tell you how to take screen shot and save it as .jpg, .png, .gif ( and so on ) file using java program.

Rectangle rectangle = new Rectangle(x, y, width, height);
// x = pixel from left
// y = pixel from top
// width = image width
// height = image height

Robot robot = new Robot();
BufferedImage image = robot.createScreenCapture(rectangle);
// Creates an image containing pixels read from the screen. This image does not include the mouse cursor and return BufferedImage object.

File file = new File(”screenshot.png”);
ImageIO.write(image, “png”, file);
// A class containing static convenience methods for locating ImageReaders and ImageWriters, and performing simple encoding and decoding.

//The code above will take screenshot according to rectangle object and it will save screenshot.png file in same folder where your java file is located.

//You can use Toolkit.getDefaultToolkit().getScreenSize() to take complete screenshot.

Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
Rectangle rectangle = new Rectangle(0, 0, size.width, size.height);

Its done! :D