views:

1235

answers:

2

I need to grab a series of screenshots and concatenate them into a movie. I'm trying to use the java Robot class to capture the screen.

But the createScreenCapture() method takes more than 1 second on my machine. I can't even get 1 fps. Is there a way to speed it up? Or is there any other API?

Edit: It is allocating a buffered image.

BufferedImage image = robot.createScreenCapture(screen); //Save the screenshot as a jpg
File file = new File("images/screen"+ index + ".jpg");
ImageIO.write(image, "jpg", file); index++;

Writing it to the jpg file takes about 200 ms where as getting BufferedImage takes about 1400ms.

+1  A: 

I'd suggest going with C or C++ for this, it has much more direct access to the hardware.

If you want the absolute maximum performance go to the driver level and just take the data straight off the video card. It's difficult to find a driver like this because it could be used to easily defeat any copy protection since it grabs the data as it's going to the screen.

But if you need to stick with Java and Robot, are you sure it's just this one function call which is taking so long? It's not allocating a BufferedImage or something else?

Yes `createScreenCapture()` does allocate a `BufferedImage`, and converts all pixels to `INT_RGBA` format, which is what takes most of the time.
finnw
A: 

Try experimenting with different screen settings. The colour depth will affect it as AWT has to convert everything to a common raster format.

Some example timings from my PC:

 Resolution | Depth | Time taken 
------------+-------+------------
 1280x1024  | 32    | 215ms
 1280x1024  | 16    | 155ms
 1600x900   | 32    | 235ms

My adapter cannot do 24bpp or 64bpp so I was unable to test with those depths, but I would guess that they would require more CPU cycles to convert.

finnw