Last active
August 29, 2015 14:04
-
-
Save DV8FromTheWorld/9b76d5fc8c664129ade2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Captures the currently selected area of the screen and sends it to the | |
| * System Clipboard as an image. | |
| * | |
| * Sets the capture button non-visible so it is not captured in the screenshot. | |
| */ | |
| private void captureArea() | |
| { | |
| btnCapture.setVisible(false); | |
| this.repaint(); | |
| //We run the screen capture in a different thread so that we can wait while | |
| //the button is becoming invisible. (We don't want the button in the image). | |
| new Thread(new Runnable() | |
| { | |
| @Override | |
| public void run() | |
| { | |
| Robot r; | |
| Point loc = pnlCapture.getLocationOnScreen(); | |
| Rectangle imageArea = new Rectangle( | |
| loc.x, loc.y, pnlCapture.getWidth(), pnlCapture.getHeight()); | |
| try | |
| { | |
| Thread.sleep(20); | |
| r = new Robot(); | |
| BufferedImage i = r.createScreenCapture(imageArea); | |
| UploaderFrame.CLIPBOARD.setContents(new ClipboardImage(i), null); | |
| } | |
| catch (InterruptedException e) | |
| { | |
| e.printStackTrace(); | |
| } | |
| catch (AWTException e) | |
| { | |
| e.printStackTrace(); | |
| } | |
| btnCapture.setVisible(true); | |
| } | |
| }).start(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment