Java截图代码模型:
import java.awt.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
import java.util.logging.*;
public class Test {
public static void main(String[] args) {
GraphicsEnvironment environment = GraphicsEnvironment
.getLocalGraphicsEnvironment();
GraphicsDevice device = environment.getDefaultScreenDevice();
try {
Robot robot = new Robot(device);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
BufferedImage image =
robot.createScreenCapture(new Rectangle(0, 0, d.width, d.height));
ImageIO.write(image, "png", new File("screen.png"));
} catch (Exception e) {
Logger.global.info(e.getMessage());
}
}
}
截图猜想: 当按下截图按钮后(快捷键), 在屏幕上画一全屏的全透明(Leopard)或者半透明(QQ)的图片, 然后用鼠标在上面选中一矩形区域, 取得矩形区域的位置与宽, 高, 然后截出图片.