Example usage for javax.imageio ImageReader canReadRaster

List of usage examples for javax.imageio ImageReader canReadRaster

Introduction

In this page you can find the example usage for javax.imageio ImageReader canReadRaster.

Prototype

public boolean canReadRaster() 

Source Link

Document

Returns true if this plug-in supports reading just a java.awt.image.Raster Raster of pixel data.

Usage

From source file:com.jaeksoft.searchlib.util.ImageUtils.java

public static ImageReader findImageReader(String formatName) {
    Iterator<ImageReader> readers = ImageIO.getImageReadersByFormatName(formatName);
    ImageReader reader = null;
    while (readers.hasNext()) {
        reader = (ImageReader) readers.next();
        if (reader.canReadRaster())
            return reader;
    }//from www . j  a v a2  s  .  co  m
    return null;
}

From source file:com.alibaba.simpleimage.codec.jpeg.JPEGDecodePerformanceTest.java

protected DecodeFacade getJDKDecoder() {
    DecodeFacade d = new DecodeFacade() {

        public BufferedImage decode(InputStream img) throws IOException {
            javax.imageio.stream.ImageInputStream stream = null;

            try {
                stream = ImageIO.createImageInputStream(img);
                Iterator<ImageReader> readers = ImageIO.getImageReaders(stream);
                ImageReader reader = null;
                while (readers.hasNext()) {
                    reader = readers.next();
                    if (reader.canReadRaster()) {
                        break;
                    }/*from   w ww  .  j  a  v  a  2 s.  c  o  m*/
                }

                reader.setInput(stream);
                BufferedImage bi = reader.read(0);

                return bi;
            } finally {
                if (stream != null) {
                    stream.close();
                }
            }
        }

        public String getName() {
            return "JDK Decoder";
        }

    };

    return d;
}

From source file:org.apache.pdfbox.filter.Filter.java

/**
 * Finds a suitable image reader for a format.
 *
 * @param formatName The format to search for.
 * @param errorCause The probably cause if something goes wrong.
 * @return The image reader for the format.
 * @throws MissingImageReaderException if no image reader is found.
 *//*from w w w  .  j  a  va  2  s .com*/
protected static ImageReader findImageReader(String formatName, String errorCause)
        throws MissingImageReaderException {
    Iterator<ImageReader> readers = ImageIO.getImageReadersByFormatName(formatName);
    ImageReader reader = null;
    while (readers.hasNext()) {
        reader = readers.next();
        if (reader.canReadRaster()) {
            break;
        }
    }
    if (reader == null) {
        throw new MissingImageReaderException("Cannot read " + formatName + " image: " + errorCause);
    }
    return reader;
}

From source file:org.sejda.sambox.pdmodel.graphics.image.JPEGFactory.java

private static BufferedImage readJpeg(Object fileOrStream) throws IOException {
    Iterator<ImageReader> readers = ImageIO.getImageReadersByFormatName("JPEG");
    ImageReader reader = null;
    while (readers.hasNext()) {
        reader = readers.next();//  w w w  . j  a  va 2  s .c o m
        if (reader.canReadRaster()) {
            break;
        }
    }
    requireIOCondition(nonNull(reader), "Cannot find an ImageIO reader for JPEG image");

    try (ImageInputStream iis = ImageIO.createImageInputStream(fileOrStream)) {
        reader.setInput(iis);
        ImageIO.setUseCache(false);
        return reader.read(0);
    } finally {
        reader.dispose();
    }
}