Create indexed color paletter, reduce colors in PNG images?

Is it possible to create indexed palette image from argb PNG image. If I load a full 32-bit argb PNG image, want to reduce colors to 256/128/32/xxx and store it as an index palette PNG image.

Possible?

Should be. Read the image with java image io, grab the pixels, calculate the palette from them, create a new BufferedImage with an appropriate ColorModel/ColorSpace, insert the pixels, write it using ImageIO.write(XXX,“png”)