Java Tutorial : How to make PC ScreenShot program with Java #2 - Multiple Shot

 


What Will I Learn?

  • You will learn How to make a Multiple 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



this is the code





public class ScreenCapture {







   /**

    * @param args the command line arguments

    */

   public static void main(String[] args) throws AWTException, IOException {

       // TODO code application logic here

// create a new Robot object  




       Robot robot = new Robot();

//get screen rectangle


       Rectangle screenRectangle = new Rectangle(Toolkit.getDefaultToolkit()                .getScreenSize());

       // create a new file

       File myFileOutput;

       int count = 0;

long beforeTime = System.currentTimeMillis();

//capture current screen and save to Screencapture


       while (count < 32) {

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

BufferedImage Screencapture = robot.createScreenCapture(screenRectangle);    
ImageIO.write(Screencapture, "png", myFileOutput);
           count++;

      }
           double time = System.currentTimeMillis() - beforeTime;

System.out.println("Seconds it took for " + count + " screen captures: " + time / 1000);

       System.out.println(count + " Images Captured!");

   }

}


This is the build  output


This is the file output



The Part #1 of this series

https://steemit.com/utopian-io/@enyason/java-tutorial-how-to-make-pc-screenshot-program-with-java-1-single-shot

H2
H3
H4
3 columns
2 columns
1 column
Join the conversation now