0

i fairly new to java and i am currently working an ambiant light for my screen. I wanted to write a programm that captures my screen and then calculates the averages of the colors at the edge of my screen.

    public class MeasureRun {
    public static void main(String[] args) {
        long start=System.currentTimeMillis();
        Rectangle screenRect1 = new Rectangle(1536,864);
        for (int i = 0; i <10; i++) {
            try {
                Robot robot = new Robot();
                BufferedImage screenLeft = robot.createScreenCapture(screenRect1);;
            } catch (AWTException ex) {
                System.err.println(ex);
            }
        }
        long end=System.currentTimeMillis();
        long elap=end-start;
        System.out.println(elap);
    }
}

This is the code i use the Capture the screen and measure how long it takes. The problem is it takes about 6 Seconds for 10 Screenshots to be made even without the calculations of the edge colors. However since i would like the colors of my ambient light to change almost simultaniously with the screen, this is obviously way to slow.

Is there any way to improve this program so that i cap more pictures per second?

krise
  • 485
  • 1
  • 10
  • 22
  • I am surprised of your execution time. I have tested this code on my machine. It takes less than 1 second. – davidxxx Feb 03 '18 at 19:47
  • Possible duplicate of [How to take a screenshot of desktop fast with Java in Windows (ffmpeg, etc.)?](https://stackoverflow.com/questions/24668407/how-to-take-a-screenshot-of-desktop-fast-with-java-in-windows-ffmpeg-etc) – Bernhard Barker Feb 03 '18 at 20:02
  • If you're not using Windows, you may still find an answer in the post linked above. – Bernhard Barker Feb 03 '18 at 20:15

0 Answers0