title: Save a GIF with index transparency using ImageIO out of an image with alpha transparency
body: <p>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.</p>
  
  <p>Using the code found under <a href="http://gman.eichberger.de/2007/07/transparent-gifs-in-java.html" rel="nofollow">http://gman.eichberger.de/2007/07/transparent-gifs-in-java.html</a>, 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).</p>
  
  <p>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?</p>
  
  <p>The way my image gets constructed:</p>
  
  <pre><code>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();
  </code></pre>
  
  <p>Thanks for any help!</p>