package com;
import java.awt.AWTEvent;
public class MyScreenCapture extends JDialog{
ImageLabel imgLabel;
int xStart=0;
int yStart=0;
int subimageX=0;
int subimageY=0;
int subimageW=0;
int subimageH=0;
private BufferedImage fullScreenImage=null;
public static void main(String[] args) {
MyScreenCapture sc=null;
try {
Thread.sleep(300);
sc=new MyScreenCapture();
} catch (Exception e) {
JOptionPane.showMessageDialog(sc, e.getMessage());
e.printStackTrace();
}
}
public MyScreenCapture() {
setUndecorated(true);
setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
setAlwaysOnTop(true);
setSize(Toolkit.getDefaultToolkit().getScreenSize());
setModal(true);
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
setPreferredSize(Toolkit.getDefaultToolkit().getScreenSize());
JPanel imgPanel = new JPanel();
getContentPane().add(imgPanel, BorderLayout.CENTER);
imgPanel.setLayout(new BorderLayout(0, 0));
imgLabel = new ImageLabel();
imgPanel.add(imgLabel, BorderLayout.CENTER);
//===============
imgLabel.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent paramMouseEvent) {
xStart=paramMouseEvent.getX();
yStart=paramMouseEvent.getY();
}
public void mouseReleased(MouseEvent paramMouseEvent) {
System.out.println("DDDDDDD");
if(paramMouseEvent.getButton()==3){
System.exit(0);
}
if(subimageY>0&&subimageX>0){
BufferedImage pickedImage = fullScreenImage.getSubimage(subimageX, subimageY, subimageW,
subimageH);
Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
MyImageTransferable it = new MyImageTransferable(new ImageIcon(pickedImage));
cb.setContents(it, it);
System.exit(0);
}
}
});
imgLabel.addMouseMotionListener(new MouseMotionListener() {
public void mouseMoved(MouseEvent paramMouseEvent) {
}
public void mouseDragged(MouseEvent paramMouseEvent) {
//paintRectOnImglabel(imgLabel.getGraphics(), paramMouseEvent.getX(),paramMouseEvent.getY());
int w=Math.abs(paramMouseEvent.getX()-xStart);
int h=Math.abs(paramMouseEvent.getY()-yStart);
int x=Math.min(xStart,paramMouseEvent.getX());
int y=Math.min(yStart,paramMouseEvent.getY());
subimageX=x;
subimageY=y;
subimageW=w;
subimageH=h;
imgLabel.drawRectangle(x, y, w, h);
}
});
setLabelIcon(imgLabel);
setVisible(true);
}
private void setLabelIcon(JLabel label){
try {
if(fullScreenImage==null){
Robot robot =new Robot();
fullScreenImage = robot.createScreenCapture(new Rectangle(Toolkit
.getDefaultToolkit().getScreenSize()));
}
ImageIcon icon = new ImageIcon(fullScreenImage);
label.setIcon(icon);
} catch (Exception e) {
e.printStackTrace();
}
}
}
class ImageLabel extends JLabel {
int lineX, lineY;
int x, y, h, w;
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawRect(x, y, w, h);
String area = Integer.toString(w) + " * " + Integer.toString(h);
g.setColor(Color.blue);
g.drawString(area, x + (int) w / 2 - 15, y + (int) h / 2);
}
public void drawRectangle(int x, int y, int width, int height) {
this.x = x;
this.y = y;
h = height;
w = width;
repaint();
}
public void drawCross(int x, int y) {
lineX = x;
lineY = y;
repaint();
}
}
class MyImageTransferable implements Transferable,ClipboardOwner{
private ImageIcon image=null;
public MyImageTransferable(ImageIcon img) {
this.image=img;
}
public void lostOwnership(Clipboard clipboard, Transferable contents) {
System.out.println("lostOwnership");
}
public Object getTransferData(DataFlavor arg0)
throws UnsupportedFlavorException, IOException {
return this.image.getImage();
}
public DataFlavor[] getTransferDataFlavors() {
DataFlavor []flavor=new DataFlavor[1];
flavor[0]=DataFlavor.imageFlavor;
return flavor;
}
public boolean isDataFlavorSupported(DataFlavor arg0) {
if(arg0.equals(DataFlavor.imageFlavor)){
System.out.println("support impageFlavor");
return true;
}
return false;
}
}
class MyAWTEvent implements AWTEventListener{
@Override
public void eventDispatched(AWTEvent paramAWTEvent) {
System.out.println("MMMMMMMMMMMMSSSSSSSS");
}
}
分享到:
相关推荐
screen capture screen capture screen capture
PX Instant Screen Capture 是一款强大的、易于使用的、直观的、非 常流行的屏幕捕捉软件。它非常适合于专业与非专业用户使用。您仅需要 使用鼠标或热键便可以快速地对屏幕进行捕捉。您捕捉的屏幕快照将可以 被自动...
FastStone Screen Capture(FSCapture)是一款很棒的图像浏览、编辑和抓屏工具,FastStone Capture支持包括BMP、JPEG、JPEG 2000、GIF、PNG、PCX、TIFF、WMF、ICO 和TGA在内的所有主流图片格式,其独有的光滑和毛刺...
Optix Screen Capture (Screenshot)
SPX Instant Screen Capture 7.0汉化版
很好用的截图软件spx Instant Screen Capture V6.0
ScreenCapture经典代码,涵盖全了
Movavi Screen Capture Studio 9 中文版主要功能: – 视频屏幕捕获: 录制程序截屏视频、在线视频、Skype 通话等 – 可自定义的捕获区域: 录制全屏、屏幕的任何部分或选定窗口 – 变速: 每秒 15 至 60 帧 – 捕获键盘...
SPX Instant Screen Capture 是最棒的截图工具超方便使用,运行时只在任务栏占一个小小的图标,不带任何主体窗口,撕边及底色效果可自定义,默认的保存路径为桌面,用过后的图不用再进文件夹可直接删除了.(支持保存为:BMP...
截图SPXInstantScreenCapture
matlab开发-screencapture。编程捕获屏幕的小实用程序
ScreenCapture.zip,利用android 5.0 API 提供完整的录制视频库
国外写的一个比较好的matlab截图代码,使用很简单,解压出来即可使用。
截图工具,支持自动截图,也可以自定义截图间隔时间,支持全屏合和幻灯片查看截图
SPX INSTANT SCREEN CAPTURE方便快捷的截图软件,可以手动设置截图方式,可以直接设置到粘贴板中,在发邮件或做电子表格时直接粘贴就可以了!!!
SPX Instant Screen Capture is a screen capture tool that brings the convenience of selecting a portion of the screen and sending it instantly to a destination of your choice, including any location on...
FoxArc Screen Capture 是一个可以替代系统屏幕截图的简单易用的轻量级屏幕捕捉程序,你可以捕获任意屏幕内容,包括矩形/椭圆形区域,窗口,对象,全屏.捕获的图片可以保存为JPG, BMP, PCX, PNG, PNM 和 TIFF格式.
screen capture Open source software. developed by some students of hcmuns in vn, it's in their "C 4 windows" course. Have fun! <br/>