1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
package imgHeberg;
import java.awt.AWTException;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import org.apache.commons.net.ftp.FTPClient;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
public class ImgHeberg {
public static void main(String[] args) {
try {
final Rectangle rectan;
Robot robot = new Robot();
final JLabel screenLabel = new JLabel();
screenLabel.addMouseMotionListener(new MouseMotionAdapter() {
Point start = new Point();
@Override
public void mouseMoved(MouseEvent me) {
start = me.getPoint();
}
@Override
public void mouseDragged(MouseEvent me) {
Point end = me.getPoint();
rectan = new Rectangle(start,
new Dimension(end.x-start.x, end.y-start.y));
}
});
int x = 0;
int y = 0;
int width = 250;
int height = 250;
Rectangle area = new Rectangle(x, y, width, height);
BufferedImage bufferedImage = robot.createScreenCapture(area);
try {
File file = new File("screenshot_small.png");
ImageIO.write(bufferedImage, "png", file);
} catch (IOException e) {
System.out.println("Error save small " + e.getMessage());
}
area = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
bufferedImage = robot.createScreenCapture(area);
try {
File file = new File("screenshot_full.png");
ImageIO.write(bufferedImage, "png", file);
} catch (IOException e) {
System.out.println("error save full " + e.getMessage());
}
} catch (AWTException e) {
System.out.println("error cap screen " + e.getMessage());
}
}
} |
Partager