Getting and Image from a Component

Hey, this is the problem:

Supose you have done a random paint on your component, for example you are drawing a fractal that evolves with respect to many parameters like a response to an internet service. How can I get this image. I know how to encode an image for save it, I just want to know how get an already drawed one.

[336 byte] By [RaulHuertasa] at [2007-11-26 22:09:48]
# 1

It could be as simple as this:

BufferedImage image = new BufferedImage(comp.getWidth(), comp.getHeight(), BufferedImage.TYPE_INT_RGB);

Graphics2D g = image.createGraphics();

comp.paint(g);

g.dispose();

ImageIO.write(image, "jpeg", new File("temp.jpeg"));

DrLaszloJamfa at 2007-7-10 10:56:53 > top of Java-index,Security,Cryptography...
# 2
> It could be as simple as this:or even simpler, type:alt-prnt scrn
tjacobs01a at 2007-7-10 10:56:53 > top of Java-index,Security,Cryptography...
# 3

Ehh... the problem with component.paint(my_g) is that the component don't have the information for redraw it, because the image was generated randomly. With Alt+PrintScreen is a good aproach but I prefer doi it programatically, I need it.

However, thank you so much, I will add 7 stars to this post :D

Thanks!!!!!!!!

RaulHuertasa at 2007-7-10 10:56:53 > top of Java-index,Security,Cryptography...
# 4
> don't have the information for redraw it, because the image was generated randomlyThen your component is designed incorrectly. If is data is generated randomly, your component could add that data to its state show that it could redraw itself.
DrLaszloJamfa at 2007-7-10 10:56:53 > top of Java-index,Security,Cryptography...
# 5
You are right Drlazlo, I can store the data in an object. Now I look as a newbie :(.Thank you so much!, thankyou!!!!!!!
RaulHuertasa at 2007-7-10 10:56:53 > top of Java-index,Security,Cryptography...