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
|
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.ImageLoader;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;
public class Snippet {
public static void main(String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setText("Capture écran");
final Table table = new Table(shell, SWT.MULTI);
table.setLinesVisible(true);
table.setBounds(10, 10, 100, 100);
for (int i = 0; i < 9; i++) {
new TableItem(table, SWT.NONE).setText("item" + i);
}
Button button = new Button(shell, SWT.PUSH);
button.setText("Capture");
button.pack();
button.setLocation(10, 140);
button.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
Point tableSize = table.getSize();
GC gc = new GC(table);
final Image image = new Image(display, tableSize.x, tableSize.y);
gc.copyArea(image, 0, 0);
gc.dispose();
ImageLoader imageLoader = new ImageLoader();
imageLoader.data = new ImageData[] {image.getImageData()};
imageLoader.save("C:/photo.jpg",SWT.IMAGE_JPEG);
image.dispose();
}
});
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}
} |
Partager