i want to capture the image of any control i.e textbox, image frame from the GUI form. Kindly notice i need the screen which only contain only one GUI item
Asked
Active
Viewed 62 times
-1
-
See [ComponentImageCapture](http://stackoverflow.com/questions/5853879/java-swing-obtain-image-of-jframe/5853992#5853992). – Andrew Thompson Dec 17 '11 at 12:26
1 Answers
1
You have to get the position and dimension of the Component, so you can create a rectangle and pass it to the Robot screenshot taker :
//Design the rectangle
Component c = somecomponent;
Rectangle rect = new Rectangle(c.getLocation(), c.getSize());
//Get the ScreenShot
Robot robot = new Robot();
BufferedImage image = robot.createScreenCapture(rect);
ImageIO.write(image, "png", new File(fileName));

aleroot
- 71,077
- 30
- 176
- 213
-
i have deal with robot class but what will happen if minimize the application – Nauman Khalid Dec 17 '11 at 14:56