Java屏幕截取
2018-07-20 来源:open-open
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 javax.imageio.ImageIO; public class CaptureScreen { public static void captureScreen(String fileName, String folder) throws Exception { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Rectangle screenRectangle = new Rectangle(screenSize); Robot robot = new Robot(); BufferedImage image = robot.createScreenCapture(screenRectangle); //保存路径 File screenFile = new File(fileName); if (!screenFile.exists()) { screenFile.mkdir(); } File f = new File(screenFile, folder); ImageIO.write(image, "png", f); //自动打开 if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.OPEN)) Desktop.getDesktop().open(f); } public static void main(String[] args) { try { captureScreen("F:\\你好","11.png"); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
上一篇:oracle表空间操作
下一篇:最小生成树C代码
最新资讯
热门推荐