Nessa classe java podemos tirar um print screen da tela e salvar em um arquivo PNG ou JPG
**
*
* @author marcelo
*/
public class PrintScreen {
public enum TIPO_IMAGEM {PNG, JPG}
private static Robot robo;
private static Rectangle screenSize;
static{
screenSize = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
try {
robo = new Robot();
} catch (AWTException ex) {
Logger.getLogger(PrintScreen.class.getName()).log(Level.SEVERE, null, ex);
}
}
public static Robot getRobo() {
return robo;
}
public static BufferedImage getPrintScreen(){
//System.out.println("getPrintScreen");
if(robo != null){
BufferedImage buff = robo.createScreenCapture(screenSize);
//System.out.println("buff:" + buff);
return buff;
}
return null;
}
public static BufferedImage getPrintScreen(int x,int y, int largura, int altura){
screenSize = new Rectangle(x, y, largura, altura);
if(robo != null){
BufferedImage buff = robo.createScreenCapture(screenSize);
return buff;
}
return null;
}
public static void savePrintFile(BufferedImage bufferedImage, File fileScreen, TIPO_IMAGEM tipoImagem){
try {
ImageIO.write(bufferedImage, tipoImagem.name(), fileScreen);
} catch (IOException ex) {
Logger.getLogger(EstacaoINFO.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
Nenhum comentário:
Postar um comentário