I understand that screen.capture() should be used in order to take screenshot using Sikuli. How can i save the image to a file?
From the resulting org.sikuli.script.ScreenImage
you can getImage
that returns a java.awt.image.BufferedImage
. To save that to a file you can use javax.imageio.ImageIO
:
ImageIO.write(screen.capture().getImage(), "jpg", new File("screen.jpg"));
Cannot comment because of reputation. Additionally, you can capture a specific region:
Region myRegion = new Region(0, 0, 250, 500);
ImageIO.write(screen.capture(myRegion).getImage(), "jpg", new File("screen.jpg"));
The region object would be defined according to your needs. In this case I created a simple region at x=0, y=0, width=250, height=500.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.