save images to disk

hi,

my graphics outputs in clientArea of Frame, on a Canvas or anything, i want to save as images *.bmp or *.jpg or anything ..

to work with ''Clipboard'' and or ''copyArea()'', then paste and save outer of my prog seems a feasable not too complex solution ..

maybe there's a comparably uncomplicated way of achieving this in java-like manner ..

up to now i got helplessly entangled in things like:

owith ''ImageProducer'' or some ''Memory[thing]Producer(?)'' i can generate an image in form of array. But that prevents graphics output drawed without array to be contained in my image.

o''WritableRenderedImage'' might be of help and i've foggy heard of ''BufferedImage'' before.

oa choice between streamed or 'randomaccessed' output will be necessary, i reckon. And for that generate a ''File'' to write to.

.. getting into any of these will entangle me into new complexities without even knowing if i'm on the right way.

't seems easy .. save to disk in image-format, what's showing in the window,

but i feel, there'll be some coding to be done ..

I'd be grateful for some hints on where or what to start with!

[1236 byte] By [RoSeventya] at [2007-11-26 14:21:37]
# 1
ImageIO.write() looks promising.
es5f2000a at 2007-7-8 2:13:24 > top of Java-index,Java Essentials,Java Programming...
# 2
looks like i'll need a RenderableImage, an ImageProducer, a WritableRaster, an ImageObserver, a File,maybe several new .. err .. 'things' for each of these ..just to access, what's already showing in my window ..
RoSeventya at 2007-7-8 2:13:24 > top of Java-index,Java Essentials,Java Programming...
# 3

final Component myComponent;

final BufferedImage myImage =

new BufferedImage(myComponent.getWidth(),

myComponent.getHeight(), BufferedImage.TYPE_INT_RGB);

final Graphics2D g2d = myImage.createGraphics();

myComponent.paint(g2d);

ImageIO.write((RenderedImage) myImage, "jpg", targetFile);

Google would have easily told you this, by the way. So would

searching the forum.

es5f2000a at 2007-7-8 2:13:24 > top of Java-index,Java Essentials,Java Programming...
# 4

yeah, but i was at a point where i di'n even know what to search for ..

(search for "Save images to disk in java" or sth alike would'nt really do it .. know what i mean ..)

your hint was really good, i know now!

by the way i found out a solution with BufferedImage java.awt.Robot.createScreenCapture(Rectangle screenRect) .. too, but i'll need lots of related Image-stuff anyway .. or get into all that in any case ..

and .. thanks for your help!

RoSeventya at 2007-7-8 2:13:24 > top of Java-index,Java Essentials,Java Programming...
# 5
createScreenCapture: watch out! This copies *from your screen*, so if another window overlaps your component of interest, you will not get what you are expecting...
DrLaszloJamfa at 2007-7-8 2:13:24 > top of Java-index,Java Essentials,Java Programming...
# 6
yeh i know .. i'll have to watch out out .. do it by button (instead menu, rightclick menu or alike that might overlap) .. but that'll do for a startbasically i needed the right direction 'to learn towards' while i got really confused by all that Image-terminology
RoSeventya at 2007-7-8 2:13:24 > top of Java-index,Java Essentials,Java Programming...