public class ImageIOGenerator extends ImageGenerator {
protected void write(ImageWrapper wrapper, ImageWriter writer, float quality, boolean alpha) throws IOException {
BufferedImage bi = wrapper.getBufferedImage();
// Set some parameters
ImageWriteParam param = writer.getDefaultWriteParam();
if (param.canWriteCompressed() &&
quality >= 0.0 && quality <= 1.0) {
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
String[] types = param.getCompressionTypes();
// If compression types are defined, but none is set, set the first one,
// since setCompressionQuality, which requires MODE_EXPLICIT to be set,
// will complain otherwise.
if (types != null && param.getCompressionType() == null) {
param.setCompressionType(types[0]);
}
param.setCompressionQuality(quality);
}
if (param.canWriteProgressive())
param.setProgressiveMode(ImageWriteParam.MODE_DISABLED);
// if bi has type ARGB and alpha is false, we have to tell the writer to not use the alpha channel:
// this is especially needed for jpeg files where imageio seems to produce wrong jpeg files right now...
if (bi.getType() == BufferedImage.TYPE_INT_ARGB
&& !alpha) {
// create a new BufferedImage that uses a WritableRaster of bi, with all the bands except the alpha band: