0

I tried just doing:

File inputFile = new File("image.tif");
BufferedImage image = ImageIO.read(inputFile);

because I thought Java 10 didn't need extra libraries to handle tiff files but the BufferedImage is null.

Mahesh M
  • 11
  • 1
  • Can you cite any sources for TIFF support in Java 10? – Raphael Schweikert Jul 02 '18 at 14:08
  • I saw in lots of posts that said that Java 9 supported it (https://stackoverflow.com/questions/29096913/read-tiff-format-in-java-eclipse near bottom), so I just assumed that Java 10 would. – Mahesh M Jul 02 '18 at 14:13
  • The above code should work with no extra imports using Java 9 and later, thanks to [JEP 262: TIFF Image I/O](http://openjdk.java.net/jeps/262). However, TIFF is an extremely flexible format, and not all variations of TIFF is supported by the standard TIFF plugin. If you attach or link a TIFF that causes this problem, I can probably give you a more detailed explanation. – Harald K Jul 03 '18 at 06:44
  • 1
    First, test the availability of a TIFF reader using `ImageIO.getImageReadersByFormatName("tiff").forEachRemaining(System.out::println);` Since the image provider doesn’t consider the file name, but the actual content, it is perfectly possible to silently get `null` for invalid files, when they are not recognized as TIFF. Request a TIFF reader explicitly to get an error feedback: `ImageReader ir = ImageIO.getImageReadersByFormatName("tiff").next(); ir.setInput(ImageIO.createImageInputStream(new File("image.tif"))); BufferedImage bi = ir.read(0);` – Holger Jul 03 '18 at 10:11

1 Answers1

-1

Since JDK 9 this should be possible:

private Image readTiffImage() throws IOException
{

final InputStream tiffImage = TiffExample.class.getResourceAsStream("image.tiff");

final BufferedImage bufferedImage = ImageIO.read(tiffImage);
final Image image = SwingFXUtils.toFXImage(bufferedImage, null);
return image;
}
Daniel Bürckner
  • 362
  • 1
  • 10