文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>用java机器人实现抓屏!

用java机器人实现抓屏!

时间:2004-10-17  来源:ilcj

import java.io.*; import java.awt.image.BufferedImage; import java.awt.*; import javax.swing.*; import java.awt.Robot; class DrawImg extends JPanel { Robot robot; BufferedImage bufImg; Image img; public DrawImg() { try { robot = new Robot(); } catch(Exception e) { e.printStackTrace(); } new Thread(new getCntImg(this)).start(); } class getCntImg implements Runnable { DrawImg di; public getCntImg(DrawImg di) { this.di = di; } public void run() { while(true) { try { bufImg = robot.createScreenCapture(new Rectangle( Toolkit.getDefaultToolkit().getScreenSize())); //将指定屏幕的象素COPY下来生成一个BufferedImage } catch(Exception e) { e.printStackTrace(); } int width = bufImg.getWidth(); int height = bufImg.getHeight(); img = bufImg.getScaledInstance(width, height, BufferedImage.TYPE_INT_RGB); try { Thread.sleep(1000); } catch(Exception e) { e.printStackTrace(); } } } } public void paintComponent(Graphics g) { super.paintComponent(g); g.drawImage(img, 0, 0, this); } } public class Robot_ extends JFrame { public Robot_() { super("screenCapture Demo"); setUndecorated(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); setSize(new java.awt.Dimension(screenSize.width, screenSize.height)); this.getContentPane().add(new DrawImg()); } public static void main(String[] args) { Robot_ robot = new Robot_(); robot.show(); } }


相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载