Posts

Showing posts from November 7, 2008

Capturing a Screenshot in Java (Using AWT)

Image
Taking a screen shot in Java, sounds interesting right. Suddenly, While Searching to internet I came across this. Here is the piece of code with which you can do this task: import java.awt.AWTException; import java.awt.Rectangle; import java.awt.Robot; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; public class ScreenCapture { public static void main(String[] args) { try { Robot robot = new Robot(); //The Size of Rectangle is Similar to Screen Resolution. BufferedImage bi=robot.createScreenCapture(new Rectangle(1280,1024)); //This will write the image to this particular location ImageIO.write(bi, "jpg", new File("C:/Ashish Docs/ScreenShot.jpg")); } catch (AWTExcepti