Example usage for org.apache.commons.imaging Imaging getImageSize

List of usage examples for org.apache.commons.imaging Imaging getImageSize

Introduction

In this page you can find the example usage for org.apache.commons.imaging Imaging getImageSize.

Prototype

public static Dimension getImageSize(final ByteSource byteSource, final Map<String, Object> params)
            throws ImageReadException, IOException 

Source Link

Usage

From source file:slash.navigation.photo.PhotoFormat.java

public void read(InputStream source, ParserContext<Wgs84Route> context) throws Exception {
    BufferedInputStream bufferedSource = new BufferedInputStream(source, READ_BUFFER_SIZE);
    bufferedSource.mark(READ_BUFFER_SIZE);

    Dimension size = Imaging.getImageSize(bufferedSource, null);
    if (size == null)
        return;//from  www. j ava2 s . co  m

    PhotoPosition position = new PhotoPosition(NotTaggable, context.getStartDate(), "No EXIF data", null);

    bufferedSource.reset();
    ImageMetadata metadata = Imaging.getMetadata(bufferedSource, null);
    TiffImageMetadata tiffImageMetadata = extractTiffImageMetadata(metadata);
    if (tiffImageMetadata != null) {
        @SuppressWarnings("unchecked")
        List<Directory> directories = (List<Directory>) tiffImageMetadata.getDirectories();
        for (Directory directory : directories)
            log.info("Reading EXIF directory " + directory);

        extendPosition(position, tiffImageMetadata, context.getStartDate());
    }

    bufferedSource.reset();
    File image = context.getFile();
    if (image == null)
        image = extractToTempFile(bufferedSource);
    position.setOrigin(image);
    position.setWaypointType(Photo);
    context.appendRoute(new Wgs84Route(this, Waypoints, new ArrayList<Wgs84Position>(singletonList(position))));
}