Getting pixel information from the screen quickly [duplicate]

℡╲_俬逩灬. 提交于 2020-04-10 18:50:50

问题


I am writing an application which needs to get the colors of pixels on the screen to run different automated tests.

(Yes, I know of the preexisting automated testing libraries. No, I can't use them.)

Currently, I'm writing in Java and the program mostly does this:

Robot r = new Robot();
for (int i = 0; i < 10; i++)
    for (int j = 0; j < 10; j++)
        r.getPixelColor(i*20, j*20);

The problem with this is that it's really slow. It takes about a second to do that scan. (10ms per pixel.) There are two problems: (1) I would like it to be fast, and (2) within a second, the screen has changed already. For various reasons, the screen only updates once every half second, so the only issue that matters is (1).

Is there any way to get pixel color information more quickly? If there are no Java libraries to do this, I'm happy to hear about C (or other) ways of doing this.


回答1:


Try using createScreenCapture(Rectangle screenRect) of Robot class to get the BufferedImage and then use getRGB(int x, int y) of BufferedImage. That should be fast




回答2:


You might want to try using r.createScreenCapture() to get the screen at once, and then iterate over the resulting image buffer. That may be faster than repeatedly calling getPixelColor(). Otherwise, definitely a C program that grabs screen capture would be faster than java.



来源:https://stackoverflow.com/questions/8350073/getting-pixel-information-from-the-screen-quickly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!