Java机器人截屏效率

huangapple 未分类评论46阅读模式
英文:

Java Robot screenshot efficiency

问题

我想创建一个小型的钢琴块游戏机器人。为此,我需要4个像素。我的问题是,当我使用Java的Robot类创建屏幕截图时,是采用获取4个单独的屏幕截图(每个截图1个像素),还是获取一个大的屏幕截图(约800 x 1个像素)会更有效率。这可能不会有太大的差别,但我只是想知道。

英文:

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.

答案1

得分: 0

以下是翻译好的部分:

测试一下:

long start = System.nanoTime();
// 拍摄4张单独的屏幕截图
System.out.println("花费时间:" + (System.nanoTime() - start));

long start = System.nanoTime();
// 拍摄一张屏幕截图
System.out.println("花费时间:" + (System.nanoTime() - start));

理想情况下,您可以将这些语句放在类似以下的循环中:

long start = System.nanoTime();
for(int i = 0; i < 一个很大的数字; i++)
    // 拍摄一张或多张屏幕截图
System.out.println("花费时间:" + (System.nanoTime() - start));
英文:

Test it yourself:

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

and

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

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

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

huangapple
  • 本文由 发表于 2020年4月5日 04:21:33
  • 转载请务必保留本文链接:https://java.coder-hub.com/61034278.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定