// obtain the writer for the image
// this must work since it is already done in the #getImageType(String) call above
ImageWriter writer = ImageIO.getImageWritersByFormatName(formatName).next();
// get default image writer parameter
ImageWriteParam param = writer.getDefaultWriteParam();
if (param.canWriteCompressed()) {
// set compression parameters if supported by writer
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
if ((param.getCompressionTypes() != null) && (param.getCompressionType() == null)) {
// a compression parameter is required but not provided, use the first one available
param.setCompressionType(param.getCompressionTypes()[0]);
}
param.setCompressionQuality(m_renderSettings.getCompressionQuality());
}
// now write the image
writer.setOutput(stream);
writer.write(null, new IIOImage(im, null, null), param);