Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Is there a efficient way to take a screenshot in Java?

843804Feb 22 2005 — edited Feb 24 2005
Hi guys.

I am planning to write a "Terminal Service" or "VNC" java program, that is Plataform-independent and efficient. So, I was planning initially to take screenshots of the screen, about 3 a second minimum.

I wrote this code, but each screenshot takes about 300ms to be taken, on a 900MHz Athlon machine, 1024x768x32Bit resolution. I need to reduce this time, is there any efficient way to do that?

My code:
Thanks for any reply!
public class ScreenShotTest {

	public ScreenShotTest() {
	}

	public static void main(String[] args) throws Exception {
		final Toolkit toolkit = Toolkit.getDefaultToolkit();
		final Dimension screenSize = toolkit.getScreenSize();
		final Rectangle screenRect = new Rectangle(screenSize);
		// create screen shot
		final Robot robot = new Robot();
		final BufferedImage image[] = new BufferedImage[10];
		for (int i = 0, index = 0; i < 10; i++) {
			final long init = System.currentTimeMillis();
			image[i] = robot.createScreenCapture(screenRect);
			final long time = System.currentTimeMillis() - init;
			System.out.println(time);
		}
		System.out.println("Finished");
	}

}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 24 2005
Added on Feb 22 2005
10 comments
968 views