Hi Ernst,

Probably the most straightforward way would be to render your
original image into an 8-bit indexed image and then send that to
ImageIO instead:

    BufferedImage img = new BufferedImage(w, h,
BufferedImage.TYPE_BYTE_INDEXED);
    Graphics g = img.createGraphics();
    g.drawImage(orig, 0, 0, null);
    g.dispose();
    ImageIO.write(img, "png", file);

The drawImage() call will take care of downsampling your original 24-
bit image into an 8-bit IndexColorModel automatically.  If you want
to have more control over the color map (or you want to create a 16-
color PNG), you can provide your own IndexColorModel when
constructing a BufferedImage, but the above code is usually
sufficient in most cases.

Chris

On Jul 26, 2007, at 3:29 AM, Ernst de Haan wrote:
I'm using Java2D (with ImageIO) to produce a PNG file. This works OK.

But how do I use Java2D to convert the image to an indexed color
format (16 or 256 colors) before writing the PNG file?

Are there are different ways of reducing the number of colors?

Cheers,


Ernst

======================================================================
=====
To unsubscribe, send email to [EMAIL PROTECTED] and include in
the body
of the message "signoff JAVA2D-INTEREST".  For general help, send
email to
[EMAIL PROTECTED] and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to