java编写截图工具

上传人:子 文档编号:42989345 上传时间:2018-06-04 格式:DOC 页数:16 大小:17.84KB
返回 下载 相关 举报
java编写截图工具_第1页
第1页 / 共16页
java编写截图工具_第2页
第2页 / 共16页
java编写截图工具_第3页
第3页 / 共16页
java编写截图工具_第4页
第4页 / 共16页
java编写截图工具_第5页
第5页 / 共16页
点击查看更多>>
资源描述

《java编写截图工具》由会员分享,可在线阅读,更多相关《java编写截图工具(16页珍藏版)》请在金锄头文库上搜索。

1、javajava 编写截图工具编写截图工具java 编写截图工具 2010-05-04 21:16/* 作者:xdj 功能:用于截取图片,方便快捷! */ 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.a

2、wt.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;

3、 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,

4、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 Rectangl

5、e rectangleCursorRU, rectangleCursorRD, rectangleCursorLU, rectangleCursorLD; private Image bis; private Dimension dimension; private Button button, button2, clearButton; private Point point = new Point3; private int width, height; private int nPoints = 5; private Panel panel; private boolean drawHa

6、sFinish = 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 clearPi

7、cture = 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(fra

8、meWidth, 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 Cu

9、rsor(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(clearBut

10、ton, 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(t

11、rue); 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); / 缓

12、存图片 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, frameHeigh

13、t, 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(MouseEv

14、ent e) if (!drawHasFinish) if (point1.x point2.x firstPointy = point2.y; if (point1.x point2.x firstPointy = point2.y; changeFirstPointX = firstPointx; changeFirstPointY = firstPointy; if (point1 != null rectangleCursorDown = new Rectangle(firstPointx + 20, firstPointy + height - 10, width - 40, 20)

15、; 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 Rectan

16、gle(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,

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 生活休闲 > 科普知识

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号