欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

java代碼實現(xiàn)截圖功能(屏幕截圖)

 更新時間:2013年12月19日 09:50:03   作者:  
java代碼實現(xiàn)截圖功能,該JavaBean可以直接在其他Java應用程序中調用,默認的文件前綴為GuiCamera,文件格式為PNG格式,直接使用下面的類吧

復制代碼 代碼如下:

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應用程序中調用,實現(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
 * @version 1.0
 *****************************************************/

public class Test
{
 private String fileName; //文件的前綴
 private String defaultName = "GuiCamera";
 static int serialNum=0;
 private String imageFormat; //圖像文件的格式
 private String defaultImageFormat="png";
 Dimension d = Toolkit.getDefaultToolkit().getScreenSize();

 /****************************************************************
 * 默認的文件前綴為GuiCamera,文件格式為PNG格式
 * The default construct will use the default
 * Image file surname "GuiCamera",
 * and default image format "png"
 ****************************************************************/
 public Test() {
 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"
 * 本構造支持JPG和PNG文件的存儲
 ****************************************************************/
 public Test(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(0, 0, (int) d.getWidth(), (int) d.getHeight()));
 serialNum++;
 //根據文件前綴變量和文件格式變量,自動生成文件名
 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)
 {
 Test cam= new Test("d:\\Hello", "png");//

 cam.snapShot();
 }
}

相關文章

  • 通過volatile驗證線程之間的可見性

    通過volatile驗證線程之間的可見性

    這篇文章主要介紹了通過volatile驗證線程之間的可見性,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2019-10-10
  • Java優(yōu)先隊列?priority?queue

    Java優(yōu)先隊列?priority?queue

    本文主要介紹了Java優(yōu)先隊列?priority?queue,優(yōu)先隊列是一種特殊的數據結構隊列中每一個元素都被分配到一個優(yōu)先權值,出隊順序按照優(yōu)先權值來劃分。一般有兩種出隊順序高優(yōu)先權出隊或低優(yōu)先權出隊,想了解具體內容的小伙伴可以參考下文內容,希望對你有所幫助
    2021-12-12
  • idea為java程序添加啟動參數的問題解析(program?arguments,vm?arguments,Environment?variable)并在程序中獲取使用

    idea為java程序添加啟動參數的問題解析(program?arguments,vm?arguments,Envi

    這篇文章主要介紹了idea為java程序添加啟動參數的問題解析(program?arguments,vm?arguments,Environment?variable)并在程序中獲取使用,本文給大家分享問題描述及解決方法,需要的朋友可以參考下
    2023-09-09
  • 解決Spring boot 整合Junit遇到的坑

    解決Spring boot 整合Junit遇到的坑

    這篇文章主要介紹了解決Spring boot 整合Junit遇到的坑,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-09-09
  • Springboot+Mybatis實現(xiàn)分頁加條件查詢功能

    Springboot+Mybatis實現(xiàn)分頁加條件查詢功能

    這篇文章主要為大家詳細介紹了Springboot+Mybatis實現(xiàn)分頁加條件查詢,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-04-04
  • Java后端面試題最新整理

    Java后端面試題最新整理

    在本篇文章里小編給大家整理了一篇關于Java后端面試題最新整理內容,需要的朋友們可以參考下。
    2020-12-12
  • Spring Cloud應用實現(xiàn)配置自動刷新過程詳解

    Spring Cloud應用實現(xiàn)配置自動刷新過程詳解

    這篇文章主要介紹了Spring Cloud應用實現(xiàn)配置自動刷新過程詳解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2019-12-12
  • Springboot項目對數據庫用戶名密碼實現(xiàn)加密過程解析

    Springboot項目對數據庫用戶名密碼實現(xiàn)加密過程解析

    這篇文章主要介紹了Springboot項目對數據庫用戶名密碼實現(xiàn)加密過程解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-06-06
  • arthas?jprofiler做復雜鏈路的調用分析

    arthas?jprofiler做復雜鏈路的調用分析

    這篇文章主要為大家介紹了arthas?jprofiler做復雜鏈路的調用分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-06-06
  • 淺談java反射和自定義注解的綜合應用實例

    淺談java反射和自定義注解的綜合應用實例

    本篇文章主要介紹了java反射和自定義注解的綜合應用,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-09-09

最新評論