Search in sources :

Example 1 with ImageDecoder

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;
}
Also used : ImageDecoder(com.sun.media.jai.codec.ImageDecoder) RenderedImage(java.awt.image.RenderedImage) BufferedImage(java.awt.image.BufferedImage) IOException(java.io.IOException)

Aggregations

ImageDecoder (com.sun.media.jai.codec.ImageDecoder)1 BufferedImage (java.awt.image.BufferedImage)1 RenderedImage (java.awt.image.RenderedImage)1 IOException (java.io.IOException)1