简体   繁体   中英

Java Robot screenshot efficiency

I want to create a little Piano Tiles bot. For this, I need 4 pixels. My question is when I´m using the Java Robot class to create the screenshot, would it be more efficient to take 4 separate screenshots (each 1 pixel) or one big screenshot (about 800 x 1 pixels). It probably won´t make such a huge difference, but I just wanna know.

Test it yourself:

long start = System.nanoTime();
// Take 4 seperate screenshots
System.out.println("Time taken: " + (System.nanoTime() - start));

and

long start = System.nanoTime();
// Take one screenshot
System.out.println("Time taken: " + (System.nanoTime() - start));

Idealy, you would put these statements in a loop like this:

long start = System.nanoTime();
for(int i = 0; i < aBigNumber; i++)
    // Take a screenshot / multiple screenshots
System.out.println("Time taken: " + (System.nanoTime() - start));

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