-1

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

Nauman Khalid
  • 852
  • 9
  • 15

1 Answers1

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