aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes   Is there a efficient way to take a screenshot in Java? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "  Is there a efficient way to take a screenshot in Java?" Watch "  Is there a efficient way to take a screenshot in Java?" New topic
Author

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

bengt hammarlund
Ranch Hand

Joined: Oct 17, 2003
Posts: 78
Hi guys.

I am planning to write a "Terminal Service" or "VNC" pure Java program (no native code), 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 (below), but each screenshot takes about 300ms to be taken, on a 900MHz Athlon machine, 1024x768x32Bit resolution. I tested then on a Athlon XP 2700+ machine, and it took about 100ms to take a 1280x1024x32Bit screenshot.

I need to reduce this time to about 30ms on a fast machine and 100ms on a slow machine (like Pentium III 500MHz), is there any way to do that?

Any ideias, code, links etc would be VERY welcome.

My code:



Thanks for any reply!


<b><i>Bengt Hammarlund</i><br />� Sun Certified Java Programmer</b>
bengt hammarlund
Ranch Hand

Joined: Oct 17, 2003
Posts: 78
another question...

I just tested the same program with the same 900MHz machine, but a 16Bit (1024x768).

The time it took for each screenshot increased!! It went to about 300ms to 400ms! Testing again on 32Bit, it took the usal 300ms. I guess my video hardware is optimized for 32Bit color...?

so, the speed of the screenshot depends on how fast is the graphics card?

Please, if you got any spare time, test this code on your machine(s) and post the avarage time for each screenshot, and your computer configuration (CPU, Graphics card).

Thanks for any help!
Igor Stojanovic
Ranch Hand

Joined: Feb 18, 2005
Posts: 58
This was my output :

190
220
160
191
150
170
160
231
170
170

Intel Pentium 4, 1600
512 Mb SDRAM
Radeon 9600 Pro, 256 Mb RAM
Resoulution, 1024*768


kind regards
Igor
bengt hammarlund
Ranch Hand

Joined: Oct 17, 2003
Posts: 78
thanks for the reply.

As you can see, it's a bit too slow for my needs. I need a faster way!
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
To my understanding the way the better VNC programs work is by installing their own video driver and capturing the native draw commands. I don't think you can do a pure Java implementation of that.
Giovanni De Stefano
Ranch Hand

Joined: Aug 17, 2004
Posts: 144
This is my output

125
109
125
141
109
125
109
110
125
109
Finished

Pentium IV HT 3.3 Ghz
512 Mb RAM
128 Mb Video

Gio :-)


SCJP 1.4
bengt hammarlund
Ranch Hand

Joined: Oct 17, 2003
Posts: 78
thanks for the replyes guys. I don't think I can do it in Java, actually. I would have to:
1) control mouse and keyboard devices from remote computer (is it possible?)
2) get screenshots, at least 3 per second, and hopefuly get from screen only what changed to send to remote computer view client (don't think it's possible too)

I think that both problems above demand native code, so a pure Java implementation is, at least in my head, impossible.

Thanks for all your help guys!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is there a efficient way to take a screenshot in Java?