take a screen shot and store it

Posted on 2004-09-07
Last Modified: 2010-03-31

Hi, I want to take a screenshot of a particular screen on on my system and store it as a jpeg. Is it possible to do this? If so how do I specify where to save the screen shot on my pc? Also is it possible to specify what program I want the jpeg (just this specific jpeg, not all jpegs on the system) to open with? in this case mozilla firebird. Thanks
Question by:VolSpeak
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 86

Accepted Solution

CEHJ earned 125 total points
ID: 12001161

Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
BufferedImage bi = new Robot.createScreenCapture(screenRect);
ImageIO.writeImage(bi, "jpg", new FileOutputStream("screen.jpg");

What program opens a jpeg is not a Java issue - it's an OS one
LVL 18

Expert Comment

ID: 12003137
You can use
to open the java file in some specific program

Author Comment

ID: 12010098

Thanks for that CEHZ, this is the code im using:

  // capture the whole screen
BufferedImage screencapture = new Robot().createScreenCapture(
   new Rectangle(10, 10, 900, 750));
   // Save as JPEG
     File file = new File("screencapture.jpg");
     ImageIO.write(screencapture, "jpg", file);

For a points increase:
 The screen I want to capture has a scroll, is it possible to include the unscrolled part of the screen in the capture as well?
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 86

Expert Comment

ID: 12010131
>>is it possible to include the unscrolled part of the screen in the capture as well?

AFAIK - no. Only what's visible. btw what kind of desktop scrolls?

Expert Comment

ID: 12010269
Its an open file, do you know of any work around?

Expert Comment

ID: 12010289
Apologies, not double accounts with one user, theres two of us using the same system....

Expert Comment

ID: 12010326
Ive just had an idea, can the resolution of the screen be changed using java so the whole file will be within the window?
LVL 86

Expert Comment

ID: 12010349
>>can the resolution of the screen be changed using java so the whole file will be within the window?

Yes, but not without JNI or a Runtime.exec call
LVL 86

Expert Comment

ID: 12111123

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
The viewer will learn how to implement Singleton Design Pattern in Java.

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question