Java Tutorial : How to make PC screenShot program with Java #1 - Single Shot

Words
233
Reading
2 min
Listen
Play
8y

                                                                 

What Will I Learn?

  • You will learn How to make a screen shot program using java classes

Requirements

  • System Requirements: Java JDK, Eclipse IDE or Netbeans IDE
  • OS Support for Java:Windows, macOS, Linux   
  • Required Knowledge A fair knowlege of java Basics and fundamentals   

Resources for Java and this tutorial:

Description

Outline and Overview 

Java provides API that allows Screen captured of your PC screen. Java robot class provides the method to enable this and it could be used to make screen shot programs or even video recorder program.

Classes needed

  1.  File - Used to create a new file
  2.  Rectangle - Used to get the Screen Dimension
  3.  Robot - Does the actual screen capture and returns  a bufferedImage object
  4. Bufferedimage - used to store the captured screen
  5. ImageIO - Used to write the buffered image to file

Before we start coding, lets create a new project

STEP 1 

// create a new file

 File myFileOutput = new File("screen.png");

STEP 2  

// create a new Robot object  

Robot robot = new Robot(); 

STEP 3

//get screen rectangle

Rectangle screenRectangle = new Rectangle(Toolkit.getDefaultToolkit()

                            .getScreenSize());

STEP4

//capture current screen and save to Screencapture

BufferedImage Screencapture = robot.createScreenCapture(screenRectangle);

STEP5

//write Screencapture to file

ImageIO.write(Screencapture, "png", myFileOutput);

This is the image of the code

Run the program and get something like this

Java Tutorial : How to make PC screenShot program with Java #1 - S... | Ecency