J2ME Animated GIF encoder

Here’s a free implementation of an animated GIF encoder for Java ME. This class is actually a porting of the original Java version, available here.

Download J2ME AnimatedGifEncoder here.

Usage is quite straightforward, and it requires these steps:

  1. Instantiate your AnimatedGifEncoder object
  2. Start it, by passing an OutputStream as argument (e.g.: a ByteArrayOutputStream)
  3. Add your Image objects by using addFrame() method
  4. Finalize it by calling finish()
ByteArrayOutputStream bos = new ByteArrayOutputStream();
 
AnimatedGifEncoder encoder = new AnimatedGifEncoder();
encoder.start(bos);
encoder.addFrame(image1);
encoder.addFrame(image2);
encoder.finish();
 
return bos.toByteArray();

As for the original version, code is free for any kind of usages, but you must refer to the Unisys LZW patent for restrictions on use of the associated LZWEncoder class.

Be Sociable, Share!