• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

creating Image

 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
i am drawing some rectangles on a jPanel. I want to make a image of this. So that each time i don't have to draw the rectangles. Is it possible. Can somebody help me.
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just create a BufferedImage, get its Graphics context and draw on it, then paint this image in your paint() method...

 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got your e-mail about wanting to save the image externally. If you have JDK 1.4 or above this is very easy with the new ImageIO class. You mentioned that you wanted to save it as a GIF. You could probably find some third party tools to write out GIF files, but writing out GIF files is not built into core Java libraries because of the stupid Unisys GIF patent licensing restrictions. (You can read GIF files however...) You can write out images as JPEG of PNG however...

You would draw to a buffered image just like in the code above, but when you are ready to save you would save it through ImageIO. Below is a short example...

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
If you want to write the image using the gif format you can use GIF89Encoder that you can find on the acme site
I've found it very simple to use. I give you a snippet of code

Hope it helps!
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic