ImageIO failed to read tiff-formatted images in Java 8

Time:2019-8-10

In Java 8 and previous versions, ImageIO in JDK fails to read image content. The solution is to use Java 9 or a third-party plug-in.

Plug-ins can be usedTwelveMonkeys ImageIOAddress: https://github.com/haraldk/Twelve Monkeys

Use methods to add dependencies to maven

<dependency>
            <groupId>com.twelvemonkeys.imageio</groupId>
            <artifactId>imageio-tiff</artifactId>
            <version>3.4.1</version>
        </dependency>

Because ImageIO automatically searches for inherited interfaces and subclasses under the classpath, there is no need to display calls. No invasion at all. Use the same method as before, for example, read TIFF files

String filename = "D:\logs\temp\test.tif";
        try {
            BufferedImage bufferedImage = ImageIO.read(FileUtil.getInputStream(filename));
            if (bufferedImage == null) {
                System.out.println("image read null");
            } else {
                System.out.println("read success");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }