This code works for "JPEG" but not "gif" or "GIF".
Why?
// repaint onto a BufferedImage
BufferedImage bufferedImage = new BufferedImage ( width + inset * 2,
height + inset * 2,
BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = (Graphics2D) (bufferedImage.createGraphics());
// redraw using our paintComponent
paintComponent( g2d );
// write out the BufferedImage as a GIF
ImageIO.write( bufferedImage,
"gif" /* format desired */,
file );

Signature
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
Roedy Green - 19 May 2004 07:45 GMT
>// repaint onto a BufferedImage
>BufferedImage bufferedImage = new BufferedImage ( width + inset * 2,
[quoted text clipped - 11 lines]
> "gif" /* format desired */,
> file );
I tried this with all 14 Image types, and each time
ImageIO.getWriterFormatNames told me only PNG and JPEG were supported,
no GIF.
I thought the Unisys GIF patent had expired.

Signature
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
Thomas Weidenfeller - 19 May 2004 09:59 GMT
> I thought the Unisys GIF patent had expired.
AFAIK, IANAL, not in all parts of the world. And once this has happened,
Sun will need some time to get it into the implementation. Taking Sun's
usual "speed" into account, I would guess we are talking years here.
/Thomas
Thomas A. Russ - 20 May 2004 19:26 GMT
> This code works for "JPEG" but not "gif" or "GIF".
>
> Why?
Because JPEG is an open standard and GIF is not.
The GIF format is protected because it uses the patented
LZW compression algorithm. That means that in order to
create GIFs, you need a license from the owner (I can't
recall offhand who that is right now).
They allow free decoding of the format, but not encoding.
That is why you won't find an easily available GIF encoder.
> // repaint onto a BufferedImage
> BufferedImage bufferedImage = new BufferedImage ( width + inset * 2,
[quoted text clipped - 10 lines]
> "gif" /* format desired */,
> file );

Signature
Thomas A. Russ, USC/Information Sciences Institute