FileDocCategorySizeDatePackage
PNGImageWriterSpi.javaAPI DocJava SE 5 API3359Fri Aug 26 14:54:42 BST 2005com.sun.imageio.plugins.png

PNGImageWriterSpi

public class PNGImageWriterSpi extends ImageWriterSpi
version
0.5

Fields Summary
private static final String
vendorName
private static final String
version
private static final String[]
names
private static final String[]
suffixes
private static final String[]
MIMETypes
private static final String
writerClassName
private static final String[]
readerSpiNames
Constructors Summary
public PNGImageWriterSpi()


      
          super(vendorName,
                version,
                names,
                suffixes,
                MIMETypes,
                writerClassName,
                STANDARD_OUTPUT_TYPE,
                readerSpiNames,
                false,
                null, null,
                null, null,
                true,
                PNGMetadata.nativeMetadataFormatName,
                "com.sun.imageio.plugins.png.PNGMetadataFormat",
                null, null
                );
    
Methods Summary
public booleancanEncodeImage(javax.imageio.ImageTypeSpecifier type)

        SampleModel sampleModel = type.getSampleModel();
        ColorModel colorModel = type.getColorModel();

        // Find the maximum bit depth across all channels
        int[] sampleSize = sampleModel.getSampleSize(); 
        int bitDepth = sampleSize[0];
        for (int i = 1; i < sampleSize.length; i++) {
            if (sampleSize[i] > bitDepth) {
                bitDepth = sampleSize[i];
            }
        }

        // Ensure bitDepth is between 1 and 16
        if (bitDepth < 1 || bitDepth > 16) {
            return false;
        }

        // Check number of bands, alpha
        int numBands = sampleModel.getNumBands();
        if (numBands < 1 || numBands > 4) {
            return false;
        }

        boolean hasAlpha = colorModel.hasAlpha();
        // Fix 4464413: PNGTransparency reg-test was failing
        // because for IndexColorModels that have alpha,
        // numBands == 1 && hasAlpha == true, thus causing
        // the check below to fail and return false.
        if (colorModel instanceof IndexColorModel) {
            return true;
        }
        if ((numBands == 1 || numBands == 3) && hasAlpha) {
            return false;
        }
        if ((numBands == 2 || numBands == 4) && !hasAlpha) {
            return false;
        }

        return true;
    
public javax.imageio.ImageWritercreateWriterInstance(java.lang.Object extension)

        return new PNGImageWriter(this);
    
public java.lang.StringgetDescription(java.util.Locale locale)

        return "Standard PNG image writer";