java屏幕捕获工具代码,java屏幕捕获工具代码大全

JAVA如何捕获和输出鼠标在屏幕上的点击呢?

这个也不是50分能解决的问题!

公司主营业务:网站制作、成都网站制作、移动网站开发等业务。帮助企业客户真正实现互联网宣传,提高企业的竞争能力。成都创新互联是一支青春激扬、勤奋敬业、活力青春激扬、勤奋敬业、活力澎湃、和谐高效的团队。公司秉承以“开放、自由、严谨、自律”为核心的企业文化,感谢他们对我们的高要求,感谢他们从不同领域给我们带来的挑战,让我们激情的团队有机会用头脑与智慧不断的给客户带来惊喜。成都创新互联推出锦州免费做网站回馈大家。

纯JAVA和程序目前没有更好的解决办法,目前JAVA可以知道鼠标当前位置,以及鼠标某处的象素颜色等有限的信息,对于鼠标的行为是没有办法捕捉的,不过ROBOT类可以驱动鼠标和键盘做一些事。

如果想达到楼主的要求,看来JNI是比较可行的办法!

如何用java实现从显示器上指定坐标抓取a*b像素的图片?

Java里面有个ToolKit的现成的截屏的东西,截出来放在BufferImage里想咋处理都行哇,不过这取到的可能是全屏,在缓冲区里可以以字节指定位置么,不过算法要自己写,应该也不会太难的,就是从一个大的字节缓冲区中,一小段一小段的根据偏移点和结束点取一行一行的字节,一个矩形区域可以由左上角一点到右下角一点决定,把这些字节拼成一个小的图像。要是不想自己写算法的话,网上一大堆呢,不过都是C代码,自己照猫画虎地写呗!

java中Scanner s = new Scanner(System.in);分别是什么意思?

Scanner是一个类,nextDouble()是Scanner的成员函数,System.in作为参数传递给Scanner的构造函数,使Scanner用键盘作为输入,然后用new在内存中实例化一个Scanner出来,使得其它变量能调用这块内存区。

Scanner类简介:

Java 5添加了java.util.Scanner类,这是一个用于扫描输入文本的新的实用程序。它是以前的StringTokenizer和Matcher类之间的某种结合。

由于任何数据都必须通过同一模式的捕获组检索或通过使用一个索引来检索文本的各个部分。于是可以结合使用正则表达式和从输入流中检索特定类型数据项的方法。

这样,除了能使用正则表达式之外,Scanner类还可以任意地对字符串和基本类型(如int和double)的数据进行分析。借助于Scanner,可以针对任何要处理的文本内容编写自定义的语法分析器。

扩展资料

System.in作为InputStream类的对象实现标准输入,可以调用它的read方法来读取键盘数据。read方法如下:

int    read()

从输入流中读取数据的下一个字节。  

Java通过系统类System实现标准输入/输出的功能,定义了3个流变量:in,out,和err.这3个流在Java中都定义为静态变量,可以直接通过System类进行调用。

System.in表示标准输入,通常指从键盘输入数据;System.out表示标准输出,通常指把数据输出到控制台或者屏幕;System.err表示标准错误输出,通常指把数据输出到控制台或者屏幕。

简单标准输入 :

System.in作为字节输入流类InputStream的对象实现标准输入,通过read()方法从键盘接受数据。

int read()

int read(byte b[])

int read(byte b[],int offset,int len)

用JAVA怎么做截屏工具?

哎~要是你给我个分就好了!我前几天刚刚做的!你拿去吧!

/*

作者:泡沫

地址:

功能:用于截取图片,方便快捷!

mail:yuhuidog#163.com (注意:其中#为@)

*/

import java.awt.AWTException;

import java.awt.BorderLayout;

import java.awt.Button;

import java.awt.Color;

import java.awt.Cursor;

import java.awt.Dimension;

import java.awt.FileDialog;

import java.awt.Frame;

import java.awt.Graphics;

import java.awt.Image;

import java.awt.Panel;

import java.awt.Point;

import java.awt.Rectangle;

import java.awt.Robot;

import java.awt.Toolkit;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.MouseEvent;

import java.awt.event.MouseListener;

import java.awt.event.MouseMotionListener;

import java.awt.image.BufferedImage;

import java.io.File;

import java.io.IOException;

import javax.imageio.ImageIO;

public class AWTpicture extends Frame implements MouseListener,MouseMotionListener,ActionListener{

private int firstX,firstY,frameWidth,frameHeight;

private int firstWith,firstHeight,firstPointx,firstPointy;

private BufferedImage bi,sbi,original;

private Robot robot;

private Rectangle rectangle;

private Rectangle rectangleCursor,rectangleCursorUp,rectangleCursorDown,rectangleCursorLeft,rectangleCursorRight;

private Rectangle rectangleCursorRU,rectangleCursorRD,rectangleCursorLU,rectangleCursorLD;

private Image bis;

private Dimension dimension;

private Button button,button2,clearButton;

private Point[] point=new Point[3];

private int width,height;

private int nPoints=5;

private Panel panel;

private boolean drawHasFinish=false,change=false;

private int changeFirstPointX,changeFirstPointY,changeWidth,changeHeight;

private boolean changeUP=false,changeDOWN=false,changeLEFT=false,changeRIGHT=false,changeRU=false,changeRD=false,changeLU=false,changeLD=false;

private boolean clearPicture=false,redraw=false;

private FileDialog fileDialog;

private AWTpicture(){

//取得屏幕大小

dimension=Toolkit.getDefaultToolkit().getScreenSize();

frameWidth=dimension.width;

frameHeight=dimension.height;

fileDialog=new FileDialog(this,"泡沫截图",FileDialog.SAVE);

rectangle=new Rectangle(frameWidth,frameHeight);

panel=new Panel();

button=new Button("退出");

button.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));

button.setBackground(Color.green);

button2=new Button("截取");

button2.setBackground(Color.darkGray);

button2.addActionListener(new MyTakePicture(this));

button2.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));

button.addActionListener(this);

clearButton=new Button("重绘");

clearButton.setBackground(Color.green);

clearButton.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));

clearButton.addActionListener(new MyClearPicture(this));

panel.setLayout(new BorderLayout());

panel.add(clearButton, BorderLayout.SOUTH);

panel.add(button, BorderLayout.NORTH);

panel.add(button2, BorderLayout.CENTER);

try {

robot=new Robot();

} catch (AWTException e) {

e.printStackTrace();

}

//截取全屏

bi=robot.createScreenCapture(rectangle);

original=bi;

this.setSize(frameWidth,frameHeight);

this.setUndecorated(true);

this.addMouseListener(this);

this.addMouseMotionListener(this);

this.add(panel,BorderLayout.EAST);

this.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));

this.setVisible(true);

this.repaint();

}

public static void main(String[] args){

new AWTpicture();

}

public void paint(Graphics g) {

this.drawR(g);

}

//缓存图片

public void update(Graphics g){

if(bis==null){

bis=this.createImage(frameWidth, frameHeight);

}

Graphics ga=bis.getGraphics();

Color c=ga.getColor();

ga.setColor(Color.black);

ga.fillRect(0, 0, frameWidth, frameHeight);

ga.setColor(c);

paint(ga);

g.drawImage(bis, 0, 0, frameWidth, frameHeight, null);

}

public void mouseClicked(MouseEvent e) {

}

public void mouseEntered(MouseEvent e) {

// TODO Auto-generated method stub

}

public void mouseExited(MouseEvent e) {

// TODO Auto-generated method stub

}

public void mousePressed(MouseEvent e) {

// TODO Auto-generated method stub

}

public void mouseReleased(MouseEvent e) {

if(!drawHasFinish){

if(point[1].xpoint[2].x point[1].ypoint[2].y){

firstPointx=point[1].x;

firstPointy=point[1].y;

}

if(point[1].xpoint[2].x point[1].ypoint[2].y){

firstPointx=point[2].x;

firstPointy=point[1].y;

}

if(point[1].xpoint[2].x point[1].ypoint[2].y){

firstPointx=point[1].x;

firstPointy=point[2].y;

}

if(point[1].xpoint[2].x point[1].ypoint[2].y){

firstPointx=point[2].x;

firstPointy=point[2].y;

}

changeFirstPointX=firstPointx;

changeFirstPointY=firstPointy;

if(point[1]!=null point[2]!=null ){

rectangleCursorUp=new Rectangle(firstPointx+20,firstPointy-10,width-40,20);

rectangleCursorDown=new Rectangle(firstPointx+20,firstPointy+height-10,width-40,20);

rectangleCursorLeft=new Rectangle(firstPointx-10,firstPointy+10,20,height-20);

rectangleCursorRight=new Rectangle(firstPointx+width-10,firstPointy+10,20,height-20);

rectangleCursorLU=new Rectangle(firstPointx-10,firstPointy-10,30,20);

rectangleCursorLD=new Rectangle(firstPointx-10,firstPointy+height-10,30,20);

rectangleCursorRU=new Rectangle(firstPointx+width-10,firstPointy-10,20,20);

rectangleCursorRD=new Rectangle(firstPointx+width-10,firstPointy+height-10,20,20);

drawHasFinish=true;

}

}

//确定每边能改变大小的矩形

if(drawHasFinish){

rectangleCursorUp=new Rectangle(changeFirstPointX+20,changeFirstPointY-10,changeWidth-40,20);

rectangleCursorDown=new Rectangle(changeFirstPointX+20,changeFirstPointY+changeHeight-10,changeWidth-40,20);

rectangleCursorLeft=new Rectangle(changeFirstPointX-10,changeFirstPointY+10,20,changeHeight-20);

rectangleCursorRight=new Rectangle(changeFirstPointX+changeWidth-10,changeFirstPointY+10,20,changeHeight-20);

rectangleCursorLU=new Rectangle(changeFirstPointX-2,changeFirstPointY-2,10,10);

rectangleCursorLD=new Rectangle(changeFirstPointX-2,changeFirstPointY+changeHeight-2,10,10);

rectangleCursorRU=new Rectangle(changeFirstPointX+changeWidth-2,changeFirstPointY-2,10,10);

rectangleCursorRD=new Rectangle(changeFirstPointX+changeWidth-2,changeFirstPointY+changeHeight-2,10,10);

}

}

public void mouseDragged(MouseEvent e) {

point[2]=e.getPoint();

//if(!drawHasFinish){

this.repaint();

// }

//托动鼠标移动大小

if(change){

if(changeUP){

changeHeight=changeHeight+changeFirstPointY-e.getPoint().y;

changeFirstPointY=e.getPoint().y;

}

if(changeDOWN){

changeHeight=e.getPoint().y-changeFirstPointY;

}

if(changeLEFT){

changeWidth=changeWidth+changeFirstPointX-e.getPoint().x;

changeFirstPointX=e.getPoint().x;

}

if(changeRIGHT){

changeWidth=e.getPoint().x-changeFirstPointX;

}

if(changeLU){

changeWidth=changeWidth+changeFirstPointX-e.getPoint().x;

changeHeight=changeHeight+changeFirstPointY-e.getPoint().y;

changeFirstPointX=e.getPoint().x;

changeFirstPointY=e.getPoint().y;

}

if(changeLD){

changeWidth=changeWidth+changeFirstPointX-e.getPoint().x;

changeHeight=e.getPoint().y-changeFirstPointY;

changeFirstPointX=e.getPoint().x;

}

if(changeRU){

changeWidth=e.getPoint().x-changeFirstPointX;

changeHeight=changeHeight+changeFirstPointY-e.getPoint().y;

changeFirstPointY=e.getPoint().y;

}

if(changeRD){

changeWidth=e.getPoint().x-changeFirstPointX;

changeHeight=e.getPoint().y-changeFirstPointY;

}

this.repaint();

}

}

public void mouseMoved(MouseEvent e) {

point[1]=e.getPoint();

//改变鼠标的形状

if(rectangleCursorUp!=null rectangleCursorUp.contains(point[1])){

this.setCursor(new Cursor(Cursor.N_RESIZE_CURSOR));

change=true;

changeUP=true;

}else if(rectangleCursorDown!=null rectangleCursorDown.contains(point[1])){

this.setCursor(new Cursor(Cursor.S_RESIZE_CURSOR));

change=true;

changeDOWN=true;

}else if(rectangleCursorLeft!=null rectangleCursorLeft.contains(point[1])){

this.setCursor(new Cursor(Cursor.W_RESIZE_CURSOR));

change=true;

changeLEFT=true;

}else if(rectangleCursorRight!=null rectangleCursorRight.contains(point[1]) ){

this.setCursor(new Cursor(Cursor.W_RESIZE_CURSOR));

change=true;

changeRIGHT=true;

}else if(rectangleCursorLU !=null rectangleCursorLU.contains(point[1])){

this.setCursor(new Cursor(Cursor.NW_RESIZE_CURSOR));

change=true;

changeLU=true;

}else if(rectangleCursorLD !=null rectangleCursorLD.contains(point[1])){

this.setCursor(new Cursor(Cursor.SW_RESIZE_CURSOR));

change=true;

changeLD=true;

}else if(rectangleCursorRU!=null rectangleCursorRU.contains(point[1])){

this.setCursor(new Cursor(Cursor.NE_RESIZE_CURSOR));

change=true;

changeRU=true;

}else if(rectangleCursorRD!=null rectangleCursorRD.contains(point[1])){

this.setCursor(new Cursor(Cursor.SE_RESIZE_CURSOR));

change=true;

changeRD=true;

}else{

this.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));

changeUP=false;changeDOWN=false;changeRIGHT=false;changeLEFT=false;changeRU=false;

changeRD=false;changeLU=false;changeLD=false;

}

redraw=false;

}

@Override

public void actionPerformed(ActionEvent e) {

System.exit(0);

}

class MyTakePicture implements ActionListener{

AWTpicture aWTpicture;

MyTakePicture(AWTpicture aWTpicture){

this.aWTpicture=aWTpicture;

}

//保存图片

public void actionPerformed(ActionEvent e) {

fileDialog.setVisible(true);

if(changeWidth0){

sbi=bi.getSubimage(changeFirstPointX,changeFirstPointY,changeWidth,changeHeight);

File file=new File(fileDialog.getDirectory());

file.mkdir();

try {

ImageIO.write(sbi, "jpeg",new File(file,fileDialog.getFile()+".jpg") );

} catch (IOException e1) {

e1.printStackTrace();

}

}

}

}

class MyClearPicture implements ActionListener{

AWTpicture aWTpicture;

MyClearPicture(AWTpicture aWTpicture){

this.aWTpicture=aWTpicture;

}

public void actionPerformed(ActionEvent e) {

drawHasFinish=false;

change=false;

redraw=true;

rectangleCursorUp=null;

rectangleCursorDown=null;

rectangleCursorLeft=null;

rectangleCursorRight=null;

rectangleCursorRU=null;

rectangleCursorRD=null;

rectangleCursorLU=null;

rectangleCursorLD=null;

changeWidth=0;

changeHeight=0;

aWTpicture.repaint();

}

}

public void drawR(Graphics g){

g.drawImage(bi, 0,0,frameWidth,frameHeight, null);

if(point[1]!=null point[2]!=null !drawHasFinish !redraw){

int[] xPoints={point[1].x,point[2].x,point[2].x,point[1].x,point[1].x};

int[] yPoints={point[1].y,point[1].y,point[2].y,point[2].y,point[1].y};

width=(point[2].x-point[1].x)0?(point[2].x-point[1].x):(point[1].x-point[2].x);

height=(point[2].y-point[1].y)0?(point[2].y-point[1].y):(point[1].y-point[2].y);

changeWidth=width;

changeHeight=height;

Color c=g.getColor();

g.setColor(Color.red);

g.drawString(width+"*"+height, point[1].x, point[1].y-5);

//画点

/*int i;

if()*/

if(point[1].xpoint[2].x point[1].ypoint[2].y){

firstPointx=point[1].x;

firstPointy=point[1].y;

}

if(point[1].xpoint[2].x point[1].ypoint[2].y){

firstPointx=point[2].x;

firstPointy=point[1].y;

}

if(point[1].xpoint[2].x point[1].ypoint[2].y){

firstPointx=point[1].x;

firstPointy=point[2].y;

}

if(point[1].xpoint[2].x point[1].ypoint[2].y){

firstPointx=point[2].x;

firstPointy=point[2].y;

}

g.fillRect(firstPointx-2,firstPointy-2 , 5,5);

g.fillRect(firstPointx+(width)/2,firstPointy-2 , 5,5);

g.fillRect(firstPointx+width-2,firstPointy-2 , 5,5);

g.fillRect(firstPointx+width-2,firstPointy+ height/2-2, 5,5);

g.fillRect(firstPointx+width-2,firstPointy+height-2, 5,5);

g.fillRect(firstPointx+(width)/2,firstPointy+height-2, 5,5);

g.fillRect(firstPointx-2,firstPointy+height-2, 5,5);

g.fillRect(firstPointx-2,firstPointy+ height/2-2, 5,5);

//画矩形

//g.drawString("fafda", point[1].x-100, point[1].y-5);

g.drawPolyline(xPoints, yPoints, nPoints);

}

if(change){

g.setColor(Color.red);

g.drawString(changeWidth+"*"+changeHeight, changeFirstPointX, changeFirstPointY-5);

g.fillRect(changeFirstPointX-2,changeFirstPointY-2 , 5,5);

g.fillRect(changeFirstPointX+(changeWidth)/2,changeFirstPointY-2 , 5,5);

g.fillRect(changeFirstPointX+changeWidth-2,changeFirstPointY-2 , 5,5);

g.fillRect(changeFirstPointX+changeWidth-2,changeFirstPointY+ changeHeight/2-2, 5,5);

g.fillRect(changeFirstPointX+changeWidth-2,changeFirstPointY+changeHeight-2, 5,5);

g.fillRect(changeFirstPointX+(changeWidth)/2,changeFirstPointY+changeHeight-2, 5,5);

g.fillRect(changeFirstPointX-2,changeFirstPointY+changeHeight-2, 5,5);

g.fillRect(changeFirstPointX-2,changeFirstPointY+ changeHeight/2-2, 5,5);

g.drawRect(changeFirstPointX, changeFirstPointY, changeWidth, changeHeight);

}

}

}


当前题目:java屏幕捕获工具代码,java屏幕捕获工具代码大全
网页网址:http://bzwzjz.com/article/dsgigep.html

其他资讯

Copyright © 2007-2020 广东宝晨空调科技有限公司 All Rights Reserved 粤ICP备2022107769号
友情链接: 高端网站设计 企业网站设计 专业网站设计 成都网站建设公司 成都网站设计 阿坝网站设计 网站设计 上市集团网站建设 H5网站制作 成都网站建设 定制网站设计 公司网站建设 高端定制网站设计 手机网站设计 重庆网站制作 成都网站建设 成都网站建设 网站制作 网站制作公司 手机网站建设 古蔺网站建设 成都网站设计