JPanel to transparent BufferImage

Hello,

I'm trying to capture a JPanel to a BufferImage. The JPanel contains a lot of transparent images that are drawn on it. I want to capture it to a BufferImage that will remain transparent, but I can't seem to figure out how to do so. Any help would be greatly appreciated.

Here is the code I'm currently using:

BufferedImage image =new BufferedImage(panel.getHeight(), panel.getWidth(), BufferedImage.TYPE_INT_ARGB);

Graphics2D g2d = image.createGraphics();

panel.paint( g2d );

g2d.dispose();

Thanks,

Collin

[605 byte] By [Ennovaa] at [2007-11-27 3:02:28]
# 1

What ever you draw directly in the JPanel can't be retreived. For do what you want look at the following trick:

//Inside your own JPanel

BufferedImage mypanel_background;

public void paint(Graphics g){

Graphics2D image = mypanel_background.createGraphics();

image.draw(...)

/*Here make all the drawing that you want to show

inside your JPanel*/

//and finally

image.dispose();

g.drawImage(image);

}

Now you have a Buffered Image to use for what ever you want

RaulHuertasa at 2007-7-12 3:45:17 > top of Java-index,Security,Cryptography...