Hi.
I'm trying to get some sort of "screenshot" from a´Graphics object to an
Image object. In detail I want to copy a tiny area from Graphics to an
Image, so that can draw this part of the Graphics representation back to
Graphics after something else was drawn there. (I have to implement a
marquee which runs over an background image)
Thanks for any hint, Noddie
IchBin - 01 Mar 2006 18:36 GMT
> Hi.
> I'm trying to get some sort of "screenshot" from a´Graphics object to an
[quoted text clipped - 4 lines]
>
> Thanks for any hint, Noddie
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());
}
}
}

Signature
Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________
'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Oliver Wong - 01 Mar 2006 20:34 GMT
> Hi.
> I'm trying to get some sort of "screenshot" from a´Graphics object to an
[quoted text clipped - 4 lines]
>
> Thanks for any hint, Noddie
The "Graphics" object is like a pen, and a "Image" object is like a
sheet of paper. That is, the drawing is stored in the "Image" object, and
not in the "Graphics" object, just like the drawing is stored on the paper,
and not in the pen.
Thus it does not make sense to take drawing data out of a Graphic object
to put into an Image object, since the Graphic object doesn't contain any
drawing data.
You need to get the surface onto which the Graphic draws upon, and get
the drawing data from that.
- Oliver
Thomas Weidenfeller - 02 Mar 2006 08:28 GMT
> I'm trying to get some sort of "screenshot" from a´Graphics object
Since Graphics objects as such don't hold any image or drawing data,
except from some state, this is not going to happen. A Graphics object
just provides a drawing context to "something". You need to get that
"something" and check if/how you can get some image data out of it.
> Image object. In detail I want to copy a tiny area from Graphics
Graphics doesn't hold image data.
/Thomas

Signature
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/