OutputStream out = new java.io.FileOutputStream(outputFile);
out = new java.io.BufferedOutputStream(out);
try {
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);