Save an image.
ImageWriter writer = null;
Iterator iter = javax.imageio.ImageIO.getImageWritersByMIMEType(mimeType);
if (iter.hasNext()) {
writer = (ImageWriter) iter.next();
}
writer.setOutput(javax.imageio.ImageIO.createImageOutputStream(os));
BufferedImage rendImage = null;
if (image instanceof BufferedImage) {
rendImage = (BufferedImage) image;
} else {
MediaTracker tracker = new MediaTracker(this);
tracker.addImage(image, 0);
tracker.waitForAll();
rendImage = new BufferedImage(image.getWidth(null), image.getHeight(null), 1);
Graphics g = rendImage.createGraphics();
g.drawImage(image, 0, 0, null);
}
writer.write(new IIOImage(rendImage, null, null));
writer.dispose();