Taking a Screenshot in JAVA
7 Message(s) by 3 Author(s) originally posted in java api
| From: Hal Vaughan |
Date: Thursday, May 03, 2007
|
I have been trying to
Google for this, but considering one of the terms
is "
screen shot," 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 do not know the graphics
API (application programming interface)too well, but I can not find a reference
to any thing in there. If I have missed the obvious, it'd certainly make
things a lot easier. I figure, though, I will need to find an
open source
class somewhere that does this.
Thanks for any help or suggestions!
Hal
| From: Andrew Thompson |
Date: Thursday, May 03, 2007
|
| From: Hal Vaughan |
Date: Thursday, May 03, 2007
|
wrote in message:
wrote in message:
I have 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 have 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.
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 hadn't used the specific
combination you did. I had tried
adding "how to" and other terms, but hadn't gotten the site you mentioned
until I added in Macro's name.
I did get a LOT of
hit s on homepages for different JAVA programs that
included screenshots of their own windows and features, though.
Hal
| From: Andrew Thompson |
Date: Friday, May 04, 2007
|
wrote in message:
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 have 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 hadn't used the specific combination you did. I had tried
adding "how to" and other terms, but hadn't gotten the site you mentioned
until I added in Macro's name.
That'd be 'Marco' and you didn't 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
| From: IchBin |
Date: Friday, May 04, 2007
|
wrote in message:
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 do not know the graphics API (application programming interface)too well, but I can not find a reference
to any thing in there. If I have missed the obvious, it'd certainly make
things a lot easier. I figure, though, I will 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-)
| From: Hal Vaughan |
Date: Friday, May 04, 2007
|
wrote in message:
wrote in message:
I have 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 have 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 hadn't used the specific combination you did. I had tried
adding "how to" and other terms, but hadn't gotten the site you mentioned
until I added in Macro's name.
That'd be 'Marco' and you didn't 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 have 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 do not 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 did not find, and I appreciate your help. I may have added
terms related to graphics and, as the result shows, the answer isn't in a
Swing or
AWT class, but in a class I had never heard of before. (Yes, I'm
self taught. I have learned all my programming except a class in
BASIC in
high school and Assembler in college years ago. I have taught myself and I
have a learning disability that sometimes makes identifying symbols, i.e.
words and letters, a
bit confusing.)
Hal
| From: Hal Vaughan |
Date: Friday, May 04, 2007
|
wrote in message:
wrote in message:
I have 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 do not know the graphics API (application programming interface)too well, but I can not find a
reference
to any thing in there. If I have missed the obvious, it'd certainly
make
things a lot easier. I figure, though, I will 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 do not know if it's a common class or
one used very often, but it isn't the place I would've expected to find
a screen capture method.
Thank you for a simple, direct answer that'd clear up any questions
quickly and provide the help I needed.
Hal
Next Message: Help with Multi Jar Files