简体   繁体   中英

java.awt.Robot - How much time screenshot takes

I just faced a strange issue; As I can get it the screen capturing code takes not-fixed time:

startTime = System.currentTimeMillis();                 

endTime   = System.currentTimeMillis();
totalTime = endTime - startTime;
System.out.println(this.getId()+" A: TIME TAKEN BETWEEN SCREENSHOTS: "+totalTime);


java.awt.image.BufferedImage image = new java.awt.Robot().createScreenCapture(new java.awt.Rectangle(250,150,500,500));

endTime   = System.currentTimeMillis();
totalTime = endTime - startTime;
System.out.println(this.getId()+" B: TIME TAKEN BETWEEN SCREENSHOTS: "+totalTime);

which is quite strange cause sometimes it is 108mls and next time it is lets say 480mls :( So its pretty hard to figure out the screenshot algorithm :S

So my question is... how to find out what time a screenshot will take or how to make screenshot time fixable (limited) in 0.5sec only?

ps

  • jre 1.7

  • jdk 1.7

  • OS: linux

Thanks

I'm not entirely sure what you are trying to accomplish, but I don't think it's likely you can limit the time the code executes, or force it to run less then 500 ms.

Maybe the following could be a solution to the problem?

You could perform the task of creating a screenshot in a different thread, then in the main thread you can check any condition you want (for instance how long it took to create the screenshot).

If the screenshot taking thread hasn't responded within the timelimit, or if other conditions have or haven't been met you can discard the result of the screenshot taking thread.

This post ( Killing thread after some specified time limit in Java ) also has some suggestion to actually kill the thread if it hasn't finished in time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM