No longer reads thumbnails, as part of the readWithOrientation method.

This commit is contained in:
Harald Kuhr 2021-01-30 16:51:25 +01:00
parent fbc738f2d4
commit 80c595cea8

View File

@ -2,6 +2,7 @@ package com.twelvemonkeys.contrib.exif;
import com.twelvemonkeys.image.ImageUtil; import com.twelvemonkeys.image.ImageUtil;
import com.twelvemonkeys.imageio.ImageReaderBase; import com.twelvemonkeys.imageio.ImageReaderBase;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
import javax.imageio.IIOImage; import javax.imageio.IIOImage;
@ -82,12 +83,11 @@ public class EXIFUtilities {
ImageReader reader = readers.next(); ImageReader reader = readers.next();
try { try {
reader.setInput(input, true, false); reader.setInput(input, true, false);
IIOImage image = reader.readAll(0, reader.getDefaultReadParam());
BufferedImage bufferedImage = ImageUtil.toBuffered(image.getRenderedImage()); IIOMetadata metadata = reader.getImageMetadata(0);
image.setRenderedImage(applyOrientation(bufferedImage, findImageOrientation(image.getMetadata()).value())); BufferedImage bufferedImage = applyOrientation(reader.read(0), findImageOrientation(metadata).value());
return image; return new IIOImage(bufferedImage, null, metadata);
} }
finally { finally {
reader.dispose(); reader.dispose();
@ -123,9 +123,15 @@ public class EXIFUtilities {
for (String arg : args) { for (String arg : args) {
File input = new File(arg); File input = new File(arg);
// Read everything (similar to ImageReader.readAll(0, null)), but applies the correct image orientation // Read everything but thumbnails (similar to ImageReader.readAll(0, null)),
// and applies the correct image orientation
IIOImage image = readWithOrientation(input); IIOImage image = readWithOrientation(input);
if (image == null) {
System.err.printf("No reader for %s%n", input);
continue;
}
// Finds the orientation as defined by the javax_imageio_1.0 format // Finds the orientation as defined by the javax_imageio_1.0 format
Orientation orientation = findImageOrientation(image.getMetadata()); Orientation orientation = findImageOrientation(image.getMetadata());