小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

小紅帽‘S BLOG—個人收藏夾、網(wǎng)文搜集、java學(xué)習(xí)、Linux技術(shù) | 用java對屏幕拷屏

 ShangShujie 2007-05-16

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;

/*******************************************************************
 * 該JavaBean可以直接在其他Java應(yīng)用程序中調(diào)用,實現(xiàn)屏幕的"拍照"
 * This JavaBean is used to snapshot the GUI in a 
 * Java application! You can embeded
 * it in to your java application source code, and us
 * it to snapshot the right GUI of the application
 * @see javax.ImageIO
 * @author liluqun ([email]liluqun@263.net[/email])
 * @version 1.0
 *
 *****************************************************/

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();

    /****************************************************************
     * 默認(rèn)的文件前綴為GuiCamera,文件格式為PNG格式
     * The default construct will use the default 
     * Image file surname "GuiCamera", 
     * and default image format "png"
     ****************************************************************/
    public GuiCamera() {
      fileName = defaultName;
      imageFormat=defaultImageFormat;
    
    }

    /****************************************************************
     * @param s the surname of the snapshot file
     * @param format the format of the  image file, 
     * it can be "jpg" or "png"
     * 本構(gòu)造支持JPG和PNG文件的存儲
     ****************************************************************/
    public GuiCamera(String s,String format) {
    
      fileName = s;
      imageFormat=format;
    }
    
    /****************************************************************
     * 對屏幕進(jìn)行拍照
     * snapShot the Gui once
     ****************************************************************/
    public void snapShot() {
    
      try {
      //拷貝屏幕到一個BufferedImage對象screenshot
        BufferedImage screenshot = (new Robot()).createScreenCapture(new
            Rectangle(0, 0, (int) d.getWidth(), (int) d.getHeight()));
        serialNum++;
        //根據(jù)文件前綴變量和文件格式變量,自動生成文件名
        String name=fileName+String.valueOf(serialNum)+"."+imageFormat;
        File f = new File(name);
        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();
    }
}

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多