Iterator iterator = ImageIO.getImageReadersByFormatName(format.toLowerCase());
if (!iterator.hasNext()) {
throw new IOException(ImageGraphics2D.class
+ ": No reader for format '" + format + "'.");
}
ImageReader reader = (ImageReader) iterator.next();
ImageInputStream iis = ImageIO.createImageInputStream(is);
reader.setInput(iis, true);
BufferedImage image = reader.read(0);
reader.dispose();
iis.close();
return image;
}