how to take screen shot of swing window

S

shrishjain

Hi All,

I want to take screen shot of Java Swing window in my program. Is that
possible?

Thanks,
Shrish
 
B

Betty

Hi All,

I want to take screen shot of Java Swing window in my program. Is that
possible?

Thanks,
Shrish


static void screenDump() {
// make a screen dump into a file with a temporary name
File dir = new File(".");
File fn;
Dimension myScreenSize = Toolkit.getDefaultToolkit().getScreenSize();
try {
fn = File.createTempFile("ScreenDump", ".jpg", dir);
String p = fn.getCanonicalPath();
BufferedImage IJ = new java.awt.Robot().createScreenCapture(new
Rectangle(new Point(0, 0),
myScreenSize));
FileOutputStream fos = new FileOutputStream(fn);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(fos);
JPEGEncodeParam par = encoder.getDefaultJPEGEncodeParam(IJ);
par.setQuality((float) 0.80, true); // use 80 percent
encoder.setJPEGEncodeParam(par);
encoder.encode(IJ);
fos.flush();
fos.close();
}
catch (AWTException e) {
e.printStackTrace();
}
catch (FileNotFoundException e) {
e.printStackTrace();
}
catch (ImageFormatException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,008
Latest member
HaroldDark

Latest Threads

Top