Created
March 3, 2021 13:57
-
-
Save iamabs2001/b50240261d4f0f1d5ad1bb66bb0fb292 to your computer and use it in GitHub Desktop.
Java Swing Screenshot
This file contains 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
// to take Jpanel of any of your component screenshot | |
void takeScreenshot() { | |
BufferedImage img = new BufferedImage(yourComponent.getWidth(), yourComponent.getHeight(), BufferedImage.TYPE_INT_RGB); | |
yourComponent.paint(img.getGraphics()); | |
File outputfile = new File("saved.png"); | |
ImageIO.write(img, "png", outputfile); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment