// If the new PNGWriter must be disabled then the other writers are used
if (disablePNG) {
super.encode(image, destination, aggressiveOutputStreamOptimization, type, map);
} else {
// Creation of the associated Writer
PNGWriter writer = new PNGWriter();
OutputStream stream = null;
try {
// writer = new PNGJWriter();
// Check if the input object is an OutputStream
if (destination instanceof OutputStream) {
boolean isScanlinePresent = writer.isScanlineSupported(image);
if (!isScanlinePresent) {
image = new ImageWorker(image).rescaleToBytes().forceComponentColorModel()
.getRenderedImage();
}
Object filterObj = null;
if (map != null) {
filterObj = map.get(FILTER_TYPE);
}
FilterType filter = null;
if (filterObj == null || !(filterObj instanceof FilterType)) {
filter = FilterType.FILTER_NONE;
} else {
filter = (FilterType) filterObj;
}
stream = (OutputStream) destination;
//Image preparation if an image helper is present
WriteHelper helper = getHelper();
RenderedImage finalImage = image;
if(helper!=null){
finalImage = helper.prepareImage(image, type);
}
// Image writing
writer.writePNG(finalImage, stream, quality, filter);
} else {
throw new IllegalArgumentException(
"Only an OutputStream can be provided to the PNGEncoder");
}
} catch (Exception e) {