<%@page contentType="text/html;charset=GBK" %><%--@ page language="java" contentType="text/html; charset=U T F-8" pageEncoding="GBK" --%>
<%--
2011-7-19 14:09:15
单jsp 服务端截屏
不依赖其他文件
--%>
<%@page import="java.awt.Dimension" %>
<%@page import="java.awt.Rectangle" %>
<%@page import="java.awt.Robot" %>
<%@page import="java.awt.Toolkit" %>
<%@page import="java.awt.image.BufferedImage" %>
<%@page import="java.io.File" %>
<%@page import="javax.imageio.ImageIO" %>
<%!
/*
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;
*/
// ntTool.ntSysOut("147:");
// captureScreen("s:\\a.png"); // 耗时 400 ms
// ntTool.ntSysOut("148:");
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, "png", new File(fileName));
}
%>
<%
out.clearBuffer(); // 清除前面的空行, 清空:
response.setContentType("image/png");
// 截屏
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));
ImageIO.write(image, "png", response.getOutputStream()); // 图像输出到页面
//
out.flush();
if( 1==1 )
return;
%>