JAVA-MANI.BLOGSPOT.COM
Tuesday, October 7, 2008
In this example you'll see how to capture a screenshot and save it into an image file such an a .png image. Some classes use in this program including the java.awt.Robot, java.awt.image.BufferedImage and javax.imageio.ImageIO.

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.awt.AWTException;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Robot;
import java.io.File;
import java.io.IOException;

public class ScreenCapture {
public static void main(String[] args) {
try {
Robot robot = new Robot();

//
// Capture screen from the top left in 200 by 200 pixel size.
//
BufferedImage bufferedImage = robot.createScreenCapture(
new Rectangle(new Dimension(200, 200)));

//
// The captured image will the writen into a file called
// screenshot.png
//
File imageFile = new File("screenshot.png");
ImageIO.write(bufferedImage, "png", imageFile);
} catch (AWTException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}

0 comments:

SUBSCRIBE VIA eMAIL

Enter your email address:

Delivered by FeedBurner

Recent Posts

Firefox 3

Counter

internet companies

Live Traffic Map

Subscribe Now