Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7647797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:33:09+00:00 2026-05-31T10:33:09+00:00

I have a BufferedImage with alpha transparency, which I need to save as GIF

  • 0

I have a BufferedImage with alpha transparency, which I need to save as GIF with index transparency. There are no semi-opague pixels, therefore a conversion should be possible.

Using the code found under http://gman.eichberger.de/2007/07/transparent-gifs-in-java.html, I define a transparency color (green, for instance, which is not part of the current image) and make it transparent. Works fine, BUT it mixes up the color table and all the colors look awful (although I only use 3 different colors).

Is there a way to adjust this or else another way of converting such an ARGB-Image to an indexed one without significant quality loss?

The way my image gets constructed:

BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics = (Graphics2D)image.getGraphics();
graphics.setColor(backgroundColor);
graphics.fillRect(0, 0, width, height);
// Some more painting here
graphics.dispose();

Thanks for any help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T10:33:10+00:00Added an answer on May 31, 2026 at 10:33 am

    Using ImageIO to handle transparency especially when saving as a GIF image is a nightmare. Transparency support in ImageIO is incomplete for different image formats and even same image format but different variations.

    If you already has a binary transparent BufferedImage, I’ve got a color quantization tool and a GIF encoder to save it as GIF with transparency. If the actual colors of the image are less than 256, no quantization will be applied. Otherwise, colors will be reduced to less than 256 but the transparent color is retained. Dithering can be applied during quantization process, so the resulting image size might be larger than usual.

    The following screenshot shows two images: the one to the left is the original PNG image with alpha channel transparency while the right hand side one is a transparent GIF image converted from the same PNG image. The GIF image is actually reduced to 128 colors but the quality is great. (PNG: 49K, GIF: 17K)

    enter image description here

    Image source: http://svg2rlg.googlecode.com/svn-history/r2/trunk/test-suite/png/butterfly.png

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a BufferedImage which is quite tall (something like 1100 pixels height) and
I have a BufferedImage which is of TYPE_BYTE_GRAY and I need to get the
I have these several images which I need to be combined using BufferedImage in
I have a BufferedImage with an IndexColorModel. I need to paint that image onto
I have a BufferedImage in my jersey post call and would like to save
I have a BufferedImage of type TYPE_INT_BGR. I need to do a pixel-by-pixel comparison
I have tried to make method which changes one color of BufferedImage to be
I have a Arraylist, which i want to save in a file for use
I have a java se 6 application which receive between 10 and 15 BufferedImage.
I have a transparent BufferedImage created with the following code(not relevant how it is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.