oli.burgess
oli.burgess

Reputation: 87

Can I export a Canvas to an image in java?

I think I'll need a buffered Image and to use a ImageOutputStream. Sorry I'm clueless, hence the lack of info here. I'm hoping for a solve-all magic method.

Upvotes: 1

Views: 2924

Answers (2)

ControlAltDel
ControlAltDel

Reputation: 35096

Canvas to BufferedImage:


Canvas c = ...
BufferedImage im = ...
Graphics g = im.getGraphics();
c.paint(g);

BufferedImage to Canvas: in paint(Graphics g) method call:


g.drawImage(im, 0, 0, null);

Upvotes: 1

Related Questions