Java Capture System screen

Source: Internet
Author: User

A simple screen capture program can Capture screenshots of the system. Share with you.

Package COM. shine. framework. screendump; import Java. AWT. dimension; import Java. AWT. rectangle; import Java. AWT. robot; import Java. AWT. toolkit; import Java. AWT. image. bufferedimage; import Java. io. file; import javax. imageIO. imageIO;/*** screenshot program ** @ author viruscodecn@gmail.com **/public class screendumphelper {Private Static string defaultimageformat = "jpg "; /*** screenshot ** @ Param filename * @ Param Format * @ Pa Ram x * @ Param y * @ Param width * @ Param height * @ throws exception */public static void snapshot (string filename, string format, int X, int y, int width, int height) throws exception {dimension D = NULL; try {d = toolkit. getdefatooltoolkit (). getscreensize (); // copy the screen to a bufferedimage object screenshotbufferedimage screenshot = (new robot ()). createscreencapture (New rectangle (X, Y, width, height); // according to the file prefix variables and File Format variable, automatically generate the file name file F = new file (filename); system. out. print ("save file" + filename); // write the screenshot object to the image file ImageIO. write (screenshot, format, f); system. out. print (".. finished! \ N ");} catch (exception ex) {Throw ex;} finally {If (D! = NULL) d = NULL;}/** screenshot ** @ Param filename * @ Param Format * @ throws exception */public static void snapshot (string filename, string format) throws exception {dimension D = NULL; try {d = toolkit. getdefatooltoolkit (). getscreensize (); snapshot (filename, format, 0, 0, D. width, D. height);} catch (exception ex) {Throw ex;} finally {If (D! = NULL) d = NULL;}/** screenshot ** @ Param filename * @ throws exception */public static void snapshot (string filename) throws exception {dimension D = NULL; try {d = toolkit. getdefatooltoolkit (). getscreensize (); snapshot (filename, defaultimageformat, 0, 0, D. width, D. height);} catch (exception ex) {Throw ex;} finally {If (D! = NULL) d = NULL ;}} public static void main (string [] A) throws exception {// capture the screendumphelper of the current screen. snapshot ("e :\\ 123.jpg ");}}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.