Java Capture Screen

In this post, I gonna show a Java Code to create an App that can capture the whole screen of your PC . Another quick tutorial on capturing your entire screen with java actually sometimes java makes me mad because sometimes i have to import loads of namespaces than c# or vb.net anyways , as usual to do something in system we import IO thingy yes we are using it here .


import java.awt.AWTException;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.*;

public class MainClass {

 public static void main(String[] args) throws AWTException, IOException {
  Robot robot=new Robot();
  BufferedImage scr=robot.createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
  ImageIO.write(scr, "JPEG", new File("img1.jpg"));
 }

}

Java.awt.Robot class is used to take the control of mouse and keyboard. Once you get the control, you can do any type of operation related to mouse and keyboard through your java code. This class is used generally for test automation.
Java Bufferd Image class is a subclass of Image class. It is used to handle and manipulate the image data. A BufferedImage is made of ColorModel of image data.
IMAGEIO class containing static convenience methods for locating ImageReaders and ImageWriters, and performing simple encoding and decoding.
Just compile the program and run then you will seen the image in the App root.

►►សូមអរគុណរាល់ការចូលរួមCommentរបស់អ្នក!

 
Top
Don't You Think this Awesome Post should be shared ??
| [Java Language] Create App to capture the entire of your screen |