converting a "Graphics" object to a "BufferedImage"

A

Arun Laksh

Hi,

I have an object of class
java.awt.Graphics
or
java.awt.Component

I need to convert the drawing in this object to an object of type "BufferedImage".

Any suggestions on how this can be done?

Below is a more detailed description of the context of the problem.

Thanks.
-Arun.


I've been using this JGraph library to draw graphs.

Ultimately I would like my drawing to be a BufferedImage object.

The JGraph library uses a JGraph object to make all the drawings.

I can do getGraphics() on that to obtain an object of Class "Graphics"
(java.awt.Graphics) from the JGraph object.

Now, I'm lookin to this to a BufferedImage object.
 
A

ak

Hi,
I have an object of class
java.awt.Graphics
or
java.awt.Component

I need to convert the drawing in this object to an object of type "BufferedImage".

Any suggestions on how this can be done?

first create BufferedImage then get Graphics from BufferedImage then paint
your component to this Graphics
 
Joined
Nov 4, 2007
Messages
1
Reaction score
0
how to turn get a Panel's Graphics into a BufferedImage

What you've said is true but I think the original poster may be looking
for something more like this

GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gs = ge.getDefaultScreenDevice();
GraphicsConfiguration gc = gs.getDefaultConfiguration();

dbImage = gc.createCompatibleImage(pWidth, pHeight, Transparency.TRANSLUCENT);

This code works well if your in writing it from inside a Class that extends
JPanel, allowing you to get the Graphics of that specific panel into a BufferedImage
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top