DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2005
    Posts
    75

    How do I convert a Graphics object into an Image object?

    I'm working within an application using JFrame, and what I want to do is create an Image, draw to the image using the methods of Graphics, and then display the image as an Icon.

    If this isn't possible (which I doubt) then how would I work with Graphics objects outside of applets?

    Thanks!

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560

    This will do the trick

    You can create a BufferedImage (height, width & type), do a getGraphics to get the graphics context and draw into it:

    Code:
    BufferedImage memImg=new BufferedImage(applet.getWidth(), applet.getHeight(),BufferedImage.TYPE_INT_RGB);
    memG=memImg.getGraphics();
    memG.setColor(.......
    Then, in the paintComponent(Graphics g) method of your image display JFrame (or JPanel) extension you draw the bufferedImage, just like an ordinary java.awt.Image.
    Last edited by sjalle; 01-10-2006 at 01:51 AM.
    eschew obfuscation

  3. #3
    Join Date
    May 2005
    Posts
    75
    Thanks sjalle It's a little rough around the edges but the image was created

Similar Threads

  1. SQL syntax error
    By Ted Young in forum Database
    Replies: 7
    Last Post: 08-07-2001, 03:53 PM
  2. Validating XML
    By Jaco de Villiers in forum XML
    Replies: 1
    Last Post: 06-01-2001, 05:50 PM
  3. Can there be an Image object array?
    By Nathan Moore in forum Web
    Replies: 0
    Last Post: 05-09-2001, 01:15 PM
  4. Replies: 3
    Last Post: 01-24-2001, 06:43 PM
  5. Object Modeling for the WEB
    By Greg Dirst in forum authorevents.appleman
    Replies: 1
    Last Post: 04-10-2000, 02:56 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links