ImageWriter writer = ImageWriterRegistry.getInstance().getWriterFor(format);
ImageWriterParams params = new ImageWriterParams();
params.setCompressionMethod(compression);
params.setResolution(72);
if (writer.supportsMultiImageWriter()) {
MultiImageWriter multiWriter = writer.createMultiImageWriter(out);
multiWriter.writeImage(createAnImage(compression, 1), params);
multiWriter.writeImage(createAnImage(compression, 2), params);
multiWriter.close();
} else {