Skip to content

Commit ecf0f9b

Browse files
committed
Introduce simple API to take a screenshot
1 parent d1859ce commit ecf0f9b

File tree

2 files changed

+37
-0
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT

2 files changed

+37
-0
lines changed

bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package org.eclipse.swt;
1616

1717

18+
import org.eclipse.swt.graphics.*;
1819
import org.eclipse.swt.internal.*;
1920
import org.eclipse.swt.widgets.*;
2021

@@ -5010,4 +5011,39 @@ public static void error (int code, Throwable throwable, String detail) {
50105011
MOD4 = 0;
50115012
}
50125013
}
5014+
5015+
/**
5016+
* Takes a screenshot of the given {@code display} and returns it as image.
5017+
*
5018+
* @param display the display to take a screenshot from
5019+
* @return the ImageData of the screenshot taken
5020+
* @since 3.130
5021+
*/
5022+
public static ImageData takeScreenShot(Display display) {
5023+
return takeScreenShot(display, display, display.getBounds());
5024+
}
5025+
5026+
/**
5027+
* Takes a screenshot of the given {@code control} and returns it as image.
5028+
*
5029+
* @param control the control to take a screenshot from
5030+
* @return the ImageData of the screenshot taken
5031+
* @since 3.130
5032+
*/
5033+
public static ImageData takeScreenShot(Control control) {
5034+
return takeScreenShot(control, control.getDisplay(), control.getBounds());
5035+
}
5036+
5037+
private static ImageData takeScreenShot(Drawable source, Display display, Rectangle bounds) {
5038+
Image image = new Image(display, bounds);
5039+
GC gc = new GC(source);
5040+
try {
5041+
gc.copyArea(image, 0, 0);
5042+
return image.getImageData();
5043+
} finally {
5044+
gc.dispose();
5045+
image.dispose();
5046+
}
5047+
}
5048+
50135049
}

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public abstract class Control extends Widget implements Drawable {
6060
long firstFixedHandle = 0;
6161
long keyController;
6262
long redrawWindow, enableWindow, provider;
63+
//TODO: derive alpha from color?
6364
int drawCount, backgroundAlpha = 255;
6465
long dragGesture, zoomGesture, rotateGesture, panGesture;
6566
Composite parent;

0 commit comments

Comments
 (0)