 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Hal Vaughan Guest
|
Posted: Fri May 04, 2007 2:25 am Post subject: Taking a Screenshot in Java |
|
|
I've been trying to Google for this, but considering one of the terms
is "screenshot," it's almost impossible to get past the noise on this. I
want to have my program take a screenshot of the entire screen when a
button in a Swing window is pressed. I do mean I need a full screenshot,
as in not just the Java windows, but everything on the screen at that time.
I admit I don't know the graphics API too well, but I can't find a reference
to any thing in there. If I've missed the obvious, it would certainly make
things a lot easier. I figure, though, I'll need to find an open source
class somewhere that does this.
Thanks for any help or suggestions!
Hal |
|
| Back to top |
|
 |
Andrew Thompson Guest
|
Posted: Fri May 04, 2007 6:06 am Post subject: Re: Taking a Screenshot in Java |
|
|
Hal Vaughan wrote:
| Quote: | I've been trying to Google for this, but considering one of the terms
is "screenshot,"
|
Mine was "java screenshot" and the top link was
to Marco Schmidt's site, and linked to a 50ish line
source that mentioned the class you need.
| Quote: | Thanks for any help or suggestions!
|
Add 'java' to any searches.
HTH
--
Andrew Thompson
http://www.athompson.info/andrew/
Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-general/200705/1 |
|
| Back to top |
|
 |
Andrew Thompson Guest
|
Posted: Fri May 04, 2007 7:11 am Post subject: Re: Taking a Screenshot in Java |
|
|
Hal Vaughan wrote:
| Quote: | I've been trying to Google for this, but considering one of the terms
is "screenshot,"
Mine was "java screenshot" and the top link was
to Marco Schmidt's site, and linked to a 50ish line
source that mentioned the class you need.
I used several different variations.
... I've also found that one's
Google results can vary depending on where they are and which Google server
it goes to.
|
Really? I, in turn never fail to *verify* that the
top 4-5 hits are identical for my 'standard search', e.g.
<http://www.google.com.au/search?hl=en&q=java+screenshot&meta=>
& the optimised and internationalised version of that URL, e.g...
<http://www.google.com/search?q=java+screenshot>
(also shorter).
And, like all other times, the first 4-5 hits (all I ever
bother checking) were the same. The top hit now is the
same as the top hit last time I checked those search terms.
it points here..
<http://schmidt.devlib.org/java/save-screenshot.html>
Where do you Google from?
| Quote: | I just searched for Marco Schmidt and Java and got his site and fount it
from there.
|
So.. you're sorted?
| Quote: | Thanks for any help or suggestions!
Add 'java' to any searches.
It was in there. Actually, I was using several different sets of search
terms, I just had not used the specific combination you did. I had tried
adding "how to" and other terms, but had not gotten the site you mentioned
until I added in Macro's name.
|
That would be 'Marco' and you did not need to add it
to the search term. His page was (and still is) the top hit
for 'java screenshot'.
Maybe you need to brush up your 'Google foo'.
--
Andrew Thompson
http://www.athompson.info/andrew/
Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-general/200705/1 |
|
| Back to top |
|
 |
Hal Vaughan Guest
|
Posted: Fri May 04, 2007 7:11 am Post subject: Re: Taking a Screenshot in Java |
|
|
Andrew Thompson wrote:
| Quote: | Hal Vaughan wrote:
I've been trying to Google for this, but considering one of the terms
is "screenshot,"
Mine was "java screenshot" and the top link was
to Marco Schmidt's site, and linked to a 50ish line
source that mentioned the class you need.
|
I used several different variations. Looking back, I also see I
used "screenshots" instead of the singular. I've also found that one's
Google results can vary depending on where they are and which Google server
it goes to.
I just searched for Marco Schmidt and Java and got his site and fount it
from there.
| Quote: | Thanks for any help or suggestions!
Add 'java' to any searches.
|
It was in there. Actually, I was using several different sets of search
terms, I just had not used the specific combination you did. I had tried
adding "how to" and other terms, but had not gotten the site you mentioned
until I added in Macro's name.
I did get a LOT of hits on homepages for different Java programs that
included screenshots of their own windows and features, though.
Hal |
|
| Back to top |
|
 |
IchBin Guest
|
Posted: Fri May 04, 2007 6:06 pm Post subject: Re: Taking a Screenshot in Java |
|
|
Hal Vaughan wrote:
| Quote: | I've been trying to Google for this, but considering one of the terms
is "screenshot," it's almost impossible to get past the noise on this. I
want to have my program take a screenshot of the entire screen when a
button in a Swing window is pressed. I do mean I need a full screenshot,
as in not just the Java windows, but everything on the screen at that time.
I admit I don't know the graphics API too well, but I can't find a reference
to any thing in there. If I've missed the obvious, it would certainly make
things a lot easier. I figure, though, I'll need to find an open source
class somewhere that does this.
Thanks for any help or suggestions!
Hal
|
OK, here is an example:
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
public class ScreenShot
{
public static void main(String[] args)
{
try
{
// Get the screen size
Dimension screenSize =
Toolkit.getDefaultToolkit().getScreenSize();
Rectangle rectangle = new Rectangle(0, 0, screenSize.width,
screenSize.height);
Robot robot = new Robot();
BufferedImage image = robot.createScreenCapture(rectangle);
File file;
// Save the screenshot as a png
file = new File("screen.png");
ImageIO.write(image, "png", file);
} catch (Exception e)
{
System.out.println(e.getMessage());
}
}
}
--
Thanks in Advance... http://weconsultants.prophp.org
IchBin, Philadelphia, Pa, USA http://ichbinquotations.awardspace.com
______________________________________________________________________
'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-) |
|
| Back to top |
|
 |
Hal Vaughan Guest
|
Posted: Sat May 05, 2007 7:10 am Post subject: Re: Taking a Screenshot in Java |
|
|
IchBin wrote:
| Quote: | Hal Vaughan wrote:
I've been trying to Google for this, but considering one of the terms
is "screenshot," it's almost impossible to get past the noise on this. I
want to have my program take a screenshot of the entire screen when a
button in a Swing window is pressed. I do mean I need a full screenshot,
as in not just the Java windows, but everything on the screen at that
time.
I admit I don't know the graphics API too well, but I can't find a
reference
to any thing in there. If I've missed the obvious, it would certainly
make
things a lot easier. I figure, though, I'll need to find an open source
class somewhere that does this.
Thanks for any help or suggestions!
Hal
OK, here is an example:
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
public class ScreenShot
{
public static void main(String[] args)
{
try
{
// Get the screen size
Dimension screenSize =
Toolkit.getDefaultToolkit().getScreenSize();
Rectangle rectangle = new Rectangle(0, 0, screenSize.width,
screenSize.height);
Robot robot = new Robot();
BufferedImage image = robot.createScreenCapture(rectangle);
File file;
// Save the screenshot as a png
file = new File("screen.png");
ImageIO.write(image, "png", file);
} catch (Exception e)
{
System.out.println(e.getMessage());
}
}
}
|
The big key that confused me is that I had looked in some Swing classes and
had never heard of the Robot class. I don't know if it's a common class or
one used very often, but it is not the place I would have expected to find
a screen capture method.
Thank you for a simple, direct answer that would clear up any questions
quickly and provide the help I needed.
Hal |
|
| Back to top |
|
 |
Hal Vaughan Guest
|
Posted: Sat May 05, 2007 7:10 am Post subject: Re: Taking a Screenshot in Java |
|
|
Andrew Thompson wrote:
| Quote: | Hal Vaughan wrote:
I've been trying to Google for this, but considering one of the terms
is "screenshot,"
Mine was "java screenshot" and the top link was
to Marco Schmidt's site, and linked to a 50ish line
source that mentioned the class you need.
I used several different variations.
... I've also found that one's
Google results can vary depending on where they are and which Google
server it goes to.
Really? I, in turn never fail to *verify* that the
top 4-5 hits are identical for my 'standard search', e.g.
http://www.google.com.au/search?hl=en&q=java+screenshot&meta=
& the optimised and internationalised version of that URL, e.g...
http://www.google.com/search?q=java+screenshot
(also shorter).
And, like all other times, the first 4-5 hits (all I ever
bother checking) were the same. The top hit now is the
same as the top hit last time I checked those search terms.
it points here..
http://schmidt.devlib.org/java/save-screenshot.html
Where do you Google from?
I just searched for Marco Schmidt and Java and got his site and fount it
from there.
So.. you're sorted?
Thanks for any help or suggestions!
Add 'java' to any searches.
It was in there. Actually, I was using several different sets of search
terms, I just had not used the specific combination you did. I had tried
adding "how to" and other terms, but had not gotten the site you mentioned
until I added in Macro's name.
That would be 'Marco' and you did not need to add it
to the search term. His page was (and still is) the top hit
for 'java screenshot'.
Maybe you need to brush up your 'Google foo'.
|
Okay, I really do appreciate your help. It pointed me to an answer I
needed. Maybe the results were because I used "screenshots" instead
of "screenshot" or maybe, when I used Java, it was at the end of my search
terms. I've also found, in the past, that I got different answers
depending on the order of the search terms. I may have even added extra
terms to all the searches. I don't remember exactly which searches I did.
To be honest, with my learning disability, it is hard for me to keep
sequences straight all the time.
I did try, I didn't find, and I appreciate your help. I may have added
terms related to graphics and, as the result shows, the answer is not in a
Swing or AWT class, but in a class I had never heard of before. (Yes, I'm
self taught. I've learned all my programming except a class in BASIC in
high school and Assembler in college years ago. I've taught myself and I
have a learning disability that sometimes makes identifying symbols, i.e.
words and letters, a bit confusing.)
Hal |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|