java截取电脑全屏
通过java代码截取电脑屏幕全屏代码如下:
1 import java.awt.AWTException; 2 import java.awt.Dimension; 3 import java.awt.Rectangle; 4 import java.awt.Robot; 5 import java.awt.Toolkit; 6 import java.awt.image.BufferedImage; 7 import java.io.File; 8 import java.io.IOException; 9 10 import javax.imageio.ImageIO; 11 12 public class SeleniumDemo { 13 14 public static void main(String args[]) throws IOException, AWTException, InterruptedException { 15 16 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 17 int screenWidth = (int) screenSize.getWidth(); 18 int screenHeight = (int) screenSize.getHeight(); 19 Robot robot=new Robot(); 20 BufferedImage bi=robot.createScreenCapture(new Rectangle(screenWidth,screenHeight)); 21 ImageIO.write(bi, "jpg", new File("C:\\Users\\XXX\\Desktop\\screen\\1.jpg")); 22 23 } 24 }