- /* 一个非常有意思的抓屏程序
- www.xiaopu.com 2001-8-1 小浦热线*/
- import java.awt.* ;
- import java.awt.image.* ;
- import java.io.* ;
- import com.sun.image.codec.jpeg.* ;
- public class SaveAsJpg{
- public SaveAsJpg(){
- }
- public static void main(String[] args) {
- try {
- BufferedImage screenshot = (new Robot()).createScreenCapture(new Rectangle(0,0,800,600)) ;
- OutputStream out = new BufferedOutputStream(new FileOutputStream ("test.jpg")) ;
- JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder (out) ;
- encoder.encode(screenshot) ;
- out.close() ;
- }catch (Exception exc) {exc.printStackTrace();}
- finally {
- System.exit(0) ;
- }
- }
- }
复制代码
|