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

in #utopian-io7 years ago

 


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

Sort:  

Mehhnn.. Boss.. Too bad... Utopian no deh upvote posts weh you use bots upvote.

thanks for the info @ubongj, i'll take note of that

sneaky-ninja-sword-xs.jpg
Sneaky Ninja Attack! You have just been defended with a 6.20% upvote!
I was summoned by @enyason. I have done their bidding and now I will vanish...

woosh
A portion of the proceeds from your bid was used in support of youarehope and tarc.

Abuse Policy
Rules
How to use Sneaky Ninja
How it works
Victim of grumpycat?