Hello,
can anyone tell me how to convert an Graphics to an Image?
I draw into a Graphic but afterwards I need the Graphic as an Image.
How do I do that?
Thank you, Rolf
Marco Schmidt - 21 Aug 2003 22:07 GMT
Rolf[SPAM].Harren:
>can anyone tell me how to convert an Graphics to an Image?
>I draw into a Graphic but afterwards I need the Graphic as an Image.
>How do I do that?
Create an Image, call its getGraphics method, draw with the Graphics
object you got that way. Drawing operations will be performed on the
image.
Regards,
Marco

Signature
Please reply in the newsgroup, not by email!
Java programming tips: http://jiu.sourceforge.net/javatips.html
Other Java pages: http://www.geocities.com/marcoschmidt.geo/java.html
Kevin Weiner - 21 Aug 2003 23:27 GMT
You can't convert a Graphics object to an Image, but if you are
using Swing, you can redraw your component onto a BufferedImage.
Create a new BufferedImage the same size as your component. Invoke
the BI's createGraphics method to obtain a Graphics context for it.
Then redraw the component on that context using SwingUtilities.paintComponent.
> Hello,
>
> can anyone tell me how to convert an Graphics to an Image?
> I draw into a Graphic but afterwards I need the Graphic as an Image.
> How do I do that?
---------------------------------------------------------------------
Kevin Weiner FM Software 610-997-3930 http://www.fmsware.com
S. Balk - 22 Aug 2003 08:34 GMT
> can anyone tell me how to convert an Graphics to an Image?
> I draw into a Graphic but afterwards I need the Graphic as an Image.
> How do I do that?
Image is the paper
Graphics is the pencil
You can't say: "I draw something with a pencil, now I want to put it on a
paper"
You have to use the Graphics *of* the Image to draw something. With one
Graphics you can draw on Image. It doesn *not* contain information about
what it painted, just like the pencil has no memory, you only have the paper
to see the result.
Rolf[SPAM].Harren - 22 Aug 2003 17:25 GMT
I will try to explain my problem in more detail:
I want to create an report, consisting of several barcodes which are
drawn at runtime. The report expects Image- Ojects.
The Images are draw by the draw methode of the Barcode.
To display the Barcode I've got the following methode:
Frame f = new Frame() {
public void paint(Graphics g) {
Barcode b = new Barcode();
b.initEan13("012345678900");
b.draw(g, 72 / 25.4 * 1, 1);
}
Can anyone tell me how to get the barcode into an Image which I can use
for the report?
Please help me, I'm very confused about all this graphics, Image,
bufferedImage stuff...
Thank you, Rolf
Rolf[SPAM].Harren - 23 Aug 2003 12:05 GMT
Perhaps you can help me with this problem:
I draw the Barcode into the Graphics of an BufferedImage.
Afterwards I convert the BufferedImage into an Image.
Why can't I display this Image??
buffimg = new BufferedImage(200,100,BufferedImage.TYPE_INT_RGB);
graph = buffimg.createGraphics();
b.initEan13("012345678900");
b.draw(graph, 72 / 25.4 * 1, 1);
Image im = Toolkit.getDefaultToolkit().createImage(buffimg.getSource());
Please help me, Rolf