The previous blog briefly describes the screenshot API of the robot class. However, there is no ready-made API to generate a screenshot with a mouse. The following is an example with a mouse screenshot.
The principle is to obtain the mouse position after screenshots. Use the java. AWT. graphics2d. drawimage method to draw the mouse. The Code is as follows:
Public class screensnapshot {public static void main (string [] ARGs) {try {Robot robot = new robot (); toolkit = toolkit. getdefatooltoolkit (); rectangle screen_area = new rectangle (Toolkit. getscreensize (); point P = mouseinfo. getpointerinfo (). getlocation (); bufferedimage screenshot = robot. createscreencapture (screen_area); string ImagePath = screensnapshot. class. getresource ("/"). getpath (). tostring (); bufferedimage cursor = ImageIO. read (new file (ImagePath + "cursor.gif"); // cursor.gif is your mouse image screenshot. creategraphics (). drawimage (cursor, P. x, p. y, null); ImageIO. write (screenshot, "jpg", new file ("C:/Cross/output.jpg"); ImageIO. write (screenshot, "PNG", new file ("C:/Cross/output.png");} catch (headlessexception e) {// todo auto-generated Catch Block E. printstacktrace ();} catch (awtexception e) {// todo auto-generated Catch Block E. printstacktrace ();} catch (ioexception e) {// todo auto-generated Catch Block E. printstacktrace ();}}}