Save a screen capture

Submitted by:Jhon Brain

Date added:28 January, 2013

Category:Java

Save a screen capture of a Java Frame/Panel/Window

Tags: screen capture

Code Snippet:

BufferedImage image = ...
System.out.println("image " + image);
File f = ...
String fileType = f.getName().substring(f.getName().lastIndexOf('.') + 1);
try {
ImageIO.write(image,fileType,f);
} catch (IOException ioe) {
ioe.printStackTrace();
JOptionPane.showMessageDialog(null,ioe,"Error",JOptionPane.ERROR_MESSAGE);
}
 
 

Comments