use of com.sun.media.jai.codec.ImageDecoder in project AozoraEpub3 by hmdev.
the class ImageUtils method readImage.
/** ストリームから画像を読み込み */
public static BufferedImage readImage(String ext, InputStream is) throws IOException {
BufferedImage image;
if (ext.equals("jpg") || ext.equals("jpeg")) {
try {
ImageDecoder dec = ImageCodec.createImageDecoder("jpeg", is, null);
RenderedImage ri = dec.decodeAsRenderedImage();
image = new BufferedImage(ri.getWidth(), ri.getHeight(), BufferedImage.TYPE_INT_RGB);
image.createGraphics().drawRenderedImage(ri, NO_TRANSFORM);
} catch (Exception e) {
image = ImageIO.read(is);
}
} else {
image = ImageIO.read(is);
}
is.close();
return image;
}
Aggregations