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

in #utopian-io6 years ago

                                                                 


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



The Video Tutorial for this :

Coin Marketplace

STEEM 0.27
TRX 0.11
JST 0.030
BTC 69650.24
ETH 3776.55
USDT 1.00
SBD 3.44