package com.zwf;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; 
public class GuiCamera 

    private String fileName; //文件的前缀 
    private String defaultName = "GuiCamera"; 
    static int serialNum=0; 
    private String imageFormat; //图像文件的格式 
    private String defaultImageFormat="png"; 
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); 
    public static String newName ;    public GuiCamera() {
      fileName = defaultName; 
      imageFormat=defaultImageFormat;     }     public GuiCamera(String s,String format) {       
      fileName = s; 
      imageFormat=format; 
    }     /**************************************************************** 
     * 对屏幕进行拍照 
     * snapShot the Gui once 
     ****************************************************************/ 
    public void snapShot() {       try { 
      //拷贝屏幕到一个BufferedImage对象screenshot 
        BufferedImage screenshot = (new Robot()).createScreenCapture(new Rectangle(100, 150, 210, 510)); 
        serialNum++; 
        //根据文件前缀变量和文件格式变量,自动生成文件名 
        String name=fileName+String.valueOf(serialNum)+"."+imageFormat; 
        File f = new File(name); 
        
        newName = name.substring(3);
        
        System.out.print("Save File "+name); 
      //将screenshot对象写入图像文件 
        ImageIO.write(screenshot, imageFormat, f); 
        System.out.print("..Finished!\n"); 
      } 
      catch (Exception ex) { 
        System.out.println(ex); 
      } 
    }     public static void main(String[] args) 
    { 
        GuiCamera cam= new GuiCamera("d:\\Hello", "png");//         cam.snapShot(); 
    } 


解决方案 »

  1.   

    没看出这个程序怎么才能通过服务器访问你这程序就是一普通的JAVA程序,运行结果就是截图,
    但你说的通过别的电脑访问,这个是什么概念,你不是把这个程序改成SERVLET让别的电脑访问想截客户机的图吧?
      

  2.   

    接触java这么长时间终于遇到让人热血的帖子了,谢谢LZ分享
    看了帖子,只有一个想法,以每秒100次的频率撞墙,直到吐血不能动为止!