convert 24 bit jpeg to 256 color gif


I have a 24 bit jpeg image which I am reading into an buffered image.
I am using BufferedImage.TYPE_INT_RGB.

Now, I have a class called GIFEncoder (downloaded, author: Adam Doppelt) which takes a BufferedImage and encodes it into gif image. But, it does not accepts 24 bit buffered image.

Should I go for another GIF Encoder which does 24 bit to 8 bit quantization also?
If yes, please tell a GIFEncoder which is freely available, can take BufferedImage as input and encodes a gif out of it.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mick BarryJava DeveloperCommented:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mayank SAssociate Director - Product EngineeringCommented:
I think you need to search for Graphics Gems II III.2 by Xialoin Wu.
Assuming your 24 bit image is in an image called "frame", you can do:

      BufferedImage indexedImage = new BufferedImage( frame.getWidth(), frame.getHeight(), BufferedImage.TYPE_BYTE_INDEXED ) ;
      Graphics g = indexedImage.getGraphics() ;
      g.drawImage( frame, 0, 0, null ) ;
      g.dispose() ;

Then, "indexedImage" contains your 256 color image which should be addable to the GifEncoder
vaibhavmishra062201Author Commented:
Thanks objects, but you forgot to mention other 2 classes used in AnimatedGifEncoder (LZWEncoder & NeuQuant)
TimYates: I tried AnimatedGifEncoder suggested by objects and it worked fine. Thanks anyway.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Graphics Software

From novice to tech pro — start learning today.