Saving an image from a Canvas

Hello,

I'm a beginner. I've created an application wich uses a native procedure, myFunc(), wich paints an image over a Canvas.

But now I want to create an Image from each frame that is painted over this Canvas. The paint method is like this one:

publicvoid paint(Graphics g){

Rectangle r = this.getBounds();

Image image = this.createImage(r.width, r.height);

Graphics g = image.getGraphics();

this.paint(g);

try{

ImageIO.write((RenderedImage)image,"png",new File(name));

}catch(IOException ioe){

// ...

}

}

It works, but it just saves a gray image, such if no image were rendered to the Canvas. What's going wrong? Thank you

[1103 byte] By [neztola] at [2007-11-26 18:11:42]
# 1

Sorry, I've changed some parts of the code for making it more comprenhensive. The correct one is:

public void paint(Graphics g) {

Rectangle r = this.getBounds();

Image image = this.createImage(r.width, r.height);

Graphics g = image.getGraphics();

this.myFunc(g);

try {

ImageIO.write((RenderedImage)image, "png", new File(name));

} catch(IOException ioe) {

// ...

}

}

myFunc(g) is the native funcion

neztola at 2007-7-9 5:44:21 > top of Java-index,Security,Cryptography...