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();
        }

 

Recommended Today

Docker learning (5) basic command of dockerfile

To learn dockerfile, you need to understand its basic commands From – base image Try to use the official reference image [x] From Tomcat: 8.5.50-jdk8-openjdk 񖓿 make reference image (based on Tomcat: 8.5.50-jdk8-openjdk) [x] From CentOS ා make a base image based on CentOS: latest [x] From scratch? Does not depend on any reference image […]