?
Solved

creating an image of a graphics object?

Posted on 2003-03-30
6
Medium Priority
?
137 Views
Last Modified: 2010-03-31
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
Comment
Question by:Unimatrix_001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 

Accepted Solution

by:
ttmoptic earned 80 total points
ID: 8234352
Image img=createImage(myWidth,myHeight);
grp=img.getGraphics();


This will give the image img, everything that is drawn on grp
0
 
LVL 3

Author Comment

by:Unimatrix_001
ID: 8234548
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
 
LVL 35

Expert Comment

by:TimYates
ID: 8235446
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
Technology Partners: 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!

 
LVL 92

Expert Comment

by:objects
ID: 8235455
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
 

Expert Comment

by:weelink
ID: 8237345
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
 
LVL 3

Author Comment

by:Unimatrix_001
ID: 8238491
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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month10 days, 14 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question