- 论坛徽章:
- 0
|
代码如下:
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
public class ScreenCapture {
/**
* @param args
*/
public static 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, "jpg", new File(fileName));
}
public static void main(String[] args) {
// TODO Auto-generated method stub
String str="c:/test.jpg";
try {
captureScreen(str);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
其中filename是要保存的文件名称
效果如图:
![]()
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/95988/showart_1936578.html |
|