Example usage for javax.imageio ImageReader getThumbnailHeight

List of usage examples for javax.imageio ImageReader getThumbnailHeight

Introduction

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

Prototype

public int getThumbnailHeight(int imageIndex, int thumbnailIndex) throws IOException 

Source Link

Document

Returns the height of the thumbnail preview image indexed by thumbnailIndex , associated with the image indexed by ImageIndex .

Usage

From source file:it.tidalwave.imageio.test.ImageReaderTestSupport.java

/*******************************************************************************************************************
 * /*from  w  w w.  java 2s.co m*/
 * 
 ******************************************************************************************************************/
protected void assertThumbnailMetadataSize(final ImageReader ir, final int thumbnailIndex, final int width,
        final int height) throws IOException {
    final Dimension thumbnailSize = new Dimension(ir.getThumbnailWidth(0, thumbnailIndex),
            ir.getThumbnailHeight(0, thumbnailIndex));
    final Dimension expectedSize = new Dimension(width, height);
    assertEquals("metadata thumbnail size: ", expectedSize, thumbnailSize);
}

From source file:org.photovault.image.ImageIOImage.java

/**
 Read the image (either original or proper thumbnail in the same file and subsample 
 it to save memory & time. The image is subsampled so that its reasolution is the
 smallest possible that is bigger than given limits. 
         /*from ww  w. j a  v a  2 s  .c  o  m*/
 @param reader The image reader that is used for reading the image
 @param minWidth Minimum width of the subsampled image
 @param minHeight Minimum height of the subsampled iamge
         
 @return Subsampled image.
 */

private RenderedImage readSubsampled(ImageReader reader, int minWidth, int minHeight) throws IOException {
    /*
     We try to ensure that the thumbnail is actually from the original image
     by comparing aspect ratio of it to original. This is not a perfect check
     but it will usually catch the most typical errors (like having a the original
     rotated by RAW conversion SW but still the original EXIF thumbnail.
     */
    double origAspect = reader.getAspectRatio(0);
    double aspectAccuracy = 0.01;
    int minInstanceSide = Math.max(minWidth, minHeight);

    int numThumbs = 0;
    RenderedImage image = null;
    try {
        int numImages = reader.getNumImages(true);
        if (numImages > 0) {
            numThumbs = reader.getNumThumbnails(0);
        }
    } catch (IOException ex) {
        ex.printStackTrace();
    }
    if (numThumbs > 0 && isOkForThumbCreation(reader.getThumbnailWidth(0, 0), reader.getThumbnailHeight(0, 0),
            minWidth, minHeight, origAspect, aspectAccuracy)) {
        // There is a thumbanil that is big enough - use it

        log.debug("Original has thumbnail, size " + reader.getThumbnailWidth(0, 0) + " x "
                + reader.getThumbnailHeight(0, 0));
        image = reader.readThumbnail(0, 0);
        log.debug("Read thumbnail");
    } else {
        log.debug("No thumbnail in original");
        ImageReadParam param = reader.getDefaultReadParam();

        // Find the maximum subsampling rate we can still use for creating
        // a quality thumbnail. Some image format readers seem to have
        // problems with subsampling values (e.g. PNG sometimes crashed
        // the whole virtual machine, to for now let's do this only
        // with JPG.
        int subsampling = 1;
        if (reader.getFormatName().equals("JPEG")) {
            int minDim = Math.min(reader.getWidth(0), reader.getHeight(0));
            while (2 * minInstanceSide * subsampling < minDim) {
                subsampling *= 2;
            }
        }
        param.setSourceSubsampling(subsampling, subsampling, 0, 0);
        image = reader.read(0, param);
    }
    return image;
}