views:

1504

answers:

7

We are trying to develop a screen capture utility.

How do we capture selected screen of another application using Java? And how do we add a callout to the captured screen?

+2  A: 

You will need to provide more specific information in order to receive meaningful help. To start with, Which operating systems does this need to work on? Do you need to capture the contents of individual windows or literally entire displays (you used the ambiguous term "selected screen of other application" in your original post). What specifically do you want to see when you "add callout to captured screen"?

Clay Fowler
+2  A: 

Perhaps the java.awt.Robot class would help with the screen shots, although I do not think it is capable of locating individual windows. As for these "call outs", the Robot class can also invoke mouse clicks and key presses, if that is what you mean.

Adam Paynter
Robot can caputure any screen region and you can figure out total screen dimension easily from the GraphicsEnvironment. You will have trouble finding the bounds of a given window without writing native code. Adding "call outs" is simply drawing a visual indication on the resulting captured image.
basszero
+1  A: 

If you want to take a screenshot of a specific window of another non-Java application code, I think you'll have to write some native (i.e. non-Java) code. Interaction between Java apps and non-Java apps at such a level is difficult.

Steve McLeod
+2  A: 
Robot r = new Robot();
Toolkit t = Toolkit.getDefaultToolkit();
Dimension d = t.getScreenSize();
Image i = r.createScreenCapture( 0, 0, d.width, d.height );

should get you a whole image of the whole screen. not sure if that gets you the whole things if you have multiple monitors, though...

John Gardner
+1  A: 

Thank you all of u.But i think i must explain my problem in more detail . Actually we are MCS Students. We are doing a project "Help Manual Builder". Which is Basically a screen capture utility which will take screeshot of any running aplication.It can be Full screen,selected area etc. This will be stored in a folder sequentially.& using this screens a HTML Page will be generated in which user can add diiffrent editing tools like callouts,text,images etc. to these screens.usg that a final help manual will be created. So can we do this capturing using core java because ROBOT class does provide selection of screen for capturing.& how to add diffrent callouts?

+3  A: 

Based on Prajakta's description of the project, I believe some explanation of manipulating a screen shot is in order (I think John did an excellent job of explaining how to capture the screen shot using the java.awt.Robot class). Remember, as Steve McLeod said, Java may not be able to automatically locate the location of the window you want to capture on the screen. This is important, because the Robot class needs to know this location, either automatically or manually from you.

Callouts, text, images, etc can be added to the screen shot via the Graphics2D object you receive when you call the createGraphics() method of the screen shot's BufferedImage. I highly recommend you check out the Graphics2D's API to better understand what it is capable of. I also recommend finding some tutorials, perhaps starting with the the 2D Graphics Tutorial from Sun. The book entitled "Filthy Rich Clients" may also come in useful.

When you finally want to save this modified screen shot, you can use the one of the "write" methods of the ImageIO class.

Here is a very simple, start-to-finish example. It is up to you to fill in whatever details necessary.

I hope this help a little!

Robot robot = new Robot();

// The hard part is knowing WHERE to capture the screen shot from
BufferedImage screenShot = robot.createScreenCapture(x, y, width, height);
Graphics2D graphics = screenShot.createGraphics();

// Add a label to the screen shot
Color textColor = Color.RED;
graphics.setColor(textColor);
graphics.drawString("Some text", textX, textY);

// Save your screen shot with its label
ImageIO.save(screenShot, "png", new File("myScreenShot.png"));
Adam Paynter
+1  A: 
OscarRyz