Graphics2D use!

Hi all,

I would like to display a buffred image on wish I added new red drawn polygons.so

JPanel comp = new JPanel();

BufferedImage img = new BufferedImage(bufOneColor.getWidth(comp),

bufOneColor.getHeight(comp), BufferedImage.TYPE_INT_RGB);

Graphics2D g2D = bufOneColor.createGraphics();

g2D.drawImage(bufOneColor, 0, 0, comp);

g2D.setColor(Color.red);

in a loop

Polygon polygon = xVect, yVect, polygonVector.size();

g2D.drawPolygon(polygon);

JFrame frame = new JFrame();

frame.getContentPane().add(comp);

comp.repaint();

frame.show();

Can you please advise me,

Thanks in advance,

[689 byte] By [emmok] at [2007-9-30 19:39:46]
# 1
The problem is that in the dispalyed frame I don't see he image!Thanks!
emmok at 2007-7-7 0:24:31 > top of Java-index,Security,Cryptography...
# 2
you should paint the bufferedImage onto the Jpanel((Graphics2D)comp.getGraphics()).drawImage(img,..<the options you prefer>..);kind regards,
Koen_casier at 2007-7-7 0:24:31 > top of Java-index,Security,Cryptography...
# 3

BUT !!!

If you only need to paint double-buffered on the JPanel, you should NOT

implement this double buffering yourself,

but you should really rely on the double buffering in the JPanel.

For doing this you should override the paintComponent-method in the JPanel

and do your painting on the graphics you get there,

since this method is already painting using double-buffering.

(The graphics you get as a parameter for this method is really the graphics of the

buffer which is flipped into the actual graphics somewhere after the method finishes).

If you need to use a double buffering (or other buffering technique)

which is self-implemented for some reason you shouldn't use a

bufferedImage, but rather a VolatileImage which is an image that tries

to use, when enabled by the configuration of the machine running on,

video-memory which is faster for graphics (certainly for flipping and copying)

than the normal memory.

You should also retrieve a new Image from the underlying graphics configuration of the JPanel

you are painting on for achieving maximum performance,

by using the following line:

Image image = comp.getGraphicsConfiguration().createCompatibleVolatileImage(....);

kind regards,

By the way, you really should use a volatileImage for double buffering.

Koen_casier at 2007-7-7 0:24:31 > top of Java-index,Security,Cryptography...