Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 140
  • Last Modified:

creating an image of a graphics object?

Hiya,

In a paint method I've got the Graphics object, grp, being passed in. However is there a way I can create an Image object of what is currently on the canvas?

Thanks
Uni
0
Unimatrix_001
Asked:
Unimatrix_001
1 Solution
 
ttmopticCommented:
Image img=createImage(myWidth,myHeight);
grp=img.getGraphics();


This will give the image img, everything that is drawn on grp
0
 
Unimatrix_001Author Commented:
Hi,

Thanks for your comment. What I was meaning was getting the things that was already on the canvas before you start to draw and shove that in the image, as opposed to creating a blank image and then drawing on that image.
0
 
TimYatesCommented:
You mean this?

http://developer.java.sun.com/developer/qow/archive/40/

Else, I think ttmoptic is right, if you just always draw to an image, then draw that image to the canvas, then you DO have an Image of what is on the canvas...
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
objectsCommented:
1.2 comes with a JPEG encoder:

FileOutputStream out = new FileOutputStream(file);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode((BufferedImage)image);
out.close();

Thers'a 3rd party encoder at:
http://www.acme.com/java/
0
 
weelinkCommented:
I haven't tested this, but it should work:

Create a bufferedimage:

BufferedImage bi = new BufferedImage(this.getWidth(), this.getHeight(), TYPE_INT_RGB);

pass it to the update method:

Graphics2D g = bi.getGraphics();
this.update(g);
0
 
Unimatrix_001Author Commented:
Thanks everybody for your comments...yes ttmoptic was right, I just totally put his answer in the wrong part of my program...Thanks again,

Uni
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now