0

I use this code to make 100 screen captures:

Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
for(int i = 0; i < 100; i++){
            BufferedImage capture = new Robot().createScreenCapture(screenRect);
            ImageIO.write(capture, "jpg", new File("D:/pictures/pic" + i + ".jpg"));
        }

Why is the cursor blinking when are taking the captures? Is something wrong in my code?

Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
Ghita
  • 23
  • 8

1 Answers1

1

No, there is nothing wrong with your code. From the Javadocs:

This image does not include the mouse cursor.

So Java hides the cursor momentarily in order to take the screenshot, then it makes it visible again.

mavroprovato
  • 8,023
  • 5
  • 37
  • 52
  • Thank you for responding me. Is there any way to not blink the cursor? – Ghita Apr 20 '15 at 15:22
  • With standard Java, I don't think so, I can't see anything relevant in the Javadocs. If you really want to do it, you should do something with JNI and the Windows C API, this may help: http://stackoverflow.com/questions/531684/what-is-the-best-way-to-take-screenshots-of-a-window-with-c-in-windows – mavroprovato Apr 20 '15 at 15:24
  • Make an invisible cursor, see http://stackoverflow.com/questions/4274606/how-to-change-cursor-icon-in-java (afterwards restore it) – Joop Eggen Apr 20 '15 at 15:25
  • I wonder why Camtasia does blink similarly. It does take the cursor into capture. – Val Apr 20 '15 at 15:35