public static PNGEncodeParam getDefaultEncodeParam(RenderedImage im) {
        ColorModel colorModel = im.getColorModel();
        if (colorModel instanceof IndexColorModel) {
            return new PNGEncodeParam.Palette();
        }

        SampleModel sampleModel = im.getSampleModel();
        int numBands = sampleModel.getNumBands();

        if (numBands == 1 || numBands == 2) {
            return new PNGEncodeParam.Gray();
        } else {
            return new PNGEncodeParam.RGB();
        }
    }
Returns an instance of <code>PNGEncodeParam.Palette</code>,
<code>PNGEncodeParam.Gray</code>, or
<code>PNGEncodeParam.RGB</code> appropriate for encoding
the given image.

<p> If the image has an <code>IndexColorModel</code>, an
instance of <code>PNGEncodeParam.Palette</code> is returned.
Otherwise, if the image has 1 or 2 bands an instance of
<code>PNGEncodeParam.Gray</code> is returned.  In all other
cases an instance of <code>PNGEncodeParam.RGB</code> is
returned.

<p> Note that this method does not provide any guarantee that
the given image will be successfully encoded by the PNG
encoder, as it only performs a very superficial analysis of
the image structure.
plugins/svg-plugin/batik-codec-fix/src/main/java/org/apache/batik/ext/awt/image/codec/png/PNGEncodeParam.java