Dalam tutorial ini, akan menunjukkan penggunaan Class Robot dan penggunaan ImageIO dalam melakukan penyimpanan.
Berikut code lengkapnya:
import java.awt.AWTException;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class Main {
public static void main (String[] args) throws AWTException, IOException{
try {
//Memperoleh Ukuran Layar
Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension screenSize = toolkit.getScreenSize();
Rectangle rect = new Rectangle(0, 0, screenSize.width, screenSize.height);
Robot robot = new Robot();
BufferedImage image = robot.createScreenCapture(rect);
File file;
//Simpan sebagai png
file = new File("capture.png");
ImageIO.write(image, "png", file);
//Simpan sebagai jpg
file = new File("capture.jpg");
ImageIO.write(image, "jpg", file);
} catch (Exception e) {
e.printStackTrace();
}
}
}
0 Response to "Melakukan Capture Screen"
Post a Comment