Java抓取屏幕缩略图

上大王 分享于 4天前 1677阅 0人收藏此代码, 我要收藏

下面的Java代码可以截取当前屏幕的缩略图

import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.io.File;
 
...
//  http://www.sharejs.com
public void captureScreen(String fileName) throws Exception {
 
   Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
   Rectangle screenRectangle = new Rectangle(screenSize);
   Robot robot = new Robot();
   BufferedImage image = robot.createScreenCapture(screenRectangle);
   ImageIO.write(image, "png", new File(fileName));
 
}
...
//该代码片段来自于: http://www.sharejs.com/codes/java/8840

标签:
  • 屏幕抓取
  • 屏幕捕获
  • Java