Reputation: 27
i am writing a program that requires me to scrape data from the screen, i am doing this by going over each pixel in the screen and saving the color but this is a very expencive opration and takes along time
the folowing code is what i am using to scrape the data
try
{
Robot r = new Robot();
for( int a = 0; a < height; a++ )
{
for ( int b = 0; b < width; b++ )
{
Color p = r.getPixelColor(a, b);
int red = p.getRed();
int blue = p.getBlue();
int green = p.getGreen();
screen[a][b][0] = red;
screen[a][b][1] = blue;
screen[a][b][2] = green;
}
}
}
catch( AWTException e ) {}
is there any way i can improve this or are there any alternatives to using this class or method
Upvotes: 0
Views: 380
Reputation: 328594
Use Robot.createScreenCapture()
to create a BufferedImage
of a specific area in a single method call.
If that doesn't work for security reasons, your second option is to modify the sources to make it render the UI in a BufferedImage
which you can then clone to analyze it (or analyze it directly if you can prevent changes to it).
Upvotes: 1