• Post Reply Bookmark Topic Watch Topic
  • New Topic

creating Image

 
satya sahu
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.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • 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 Java Spring
  • 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...

 
Igor Zeta
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!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!