Last active
December 10, 2015 08:48
-
-
Save jesusnoseq/4409638 to your computer and use it in GitHub Desktop.
Este programa hace un determinado numero de capturas de pantalla, las guarda
como ficheros jpg y termina.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.Rectangle; | |
import java.awt.Robot; | |
import java.awt.Toolkit; | |
import java.awt.image.BufferedImage; | |
import java.io.File; | |
import javax.imageio.ImageIO; | |
/** | |
Este programa hace un determinado numero de capturas de pantalla, las guarda | |
como ficheros jpg y termina. | |
*/ | |
public class CaptureScreen | |
{ | |
public static void main(String[] args) throws Exception | |
{ | |
// numero de iteraciones | |
int iteracions=20; | |
// numero de capturas por segundo | |
double fps=0.5; | |
//tiempo calculado que hay que esperar entre captura y captura | |
long waitTime=(long) (1000/fps); | |
// el tiempo el programa estara capturando el escritorio sera: | |
// iteracions*fps segundos | |
// sin tener en cuenta el tiempo que se tarda en realizar la captura | |
// y guardarla | |
Robot r=new Robot(); | |
// Se puede indicar que zona de la pantalla capturar, en este caso | |
// se capturara toda la pantalla | |
Rectangle captureSize = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()); | |
BufferedImage bufImg; | |
for(int i=0; i<iteracions; i++) | |
{ | |
// toma la captura | |
bufImg= r.createScreenCapture(captureSize); | |
// y la guarda como una imagen jpg | |
// el nombre del fichero lleva el numero de la captura | |
ImageIO.write(bufImg, "jpg", new File("screen"+i+".jpg")); | |
// System.out.println("Captura "+i+" guardada."); | |
Thread.sleep(waitTime); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment